﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class Main_Inventory_PurInvoiceWithItemLevel : System.Web.UI.Page
{
    //For the Global Variable
    #region
    Datautility DU = new Datautility();
    CommonLog Log = new CommonLog();
    //pageid=449;
    string strsql = "";
    string IP = "";
    int tblItemsCounter = 0;//Declare Counter for - No discount and tax at item level
    int tblImportCounter = 0;
    string PurchaseReceive = "";
    string PurchaseReceiveMain = "";
    string PurchaseReceiveDetails = "";
    string PurchaseReceiveItem = "";
    string PurchaseReceiveTotal = "";
    string PurchaseReceiveOthers = "";
    string PurchaseReceiveDelivery = "";
    double saleamt = 0.0; double subamt = 0.0;
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        //*********Bind Purchase Order Items***********By Harish  
        if (Request.QueryString["Poid"] != null && Convert.ToInt32(Request.QueryString["Currency"]) == 1)//For Domestic
        {
            string Pagepermission = "select PAGE_ID,PAGE_ADD,USERID,USERNAME as EmailID from USER_PERMISSION inner join LOGIN on USER_PERMISSION.USER_ID=LOGIN.USERID where USER_ID='" + Session["userid"].ToString() + "' and PAGE_ID=449";
            DataTable dt = DU.getdata(Pagepermission);
            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["PAGE_ADD"].ToString() == "True")
                {
                    BindPOTaxItemLevel();//For Domestic;
                    Bind_DDLTaxGroup();
                    lblFolioNo.Visible = false;
                    txtfolioNo.Visible = false;
                    tabImport.Style["display"] = "none";
                    calImport.Style["display"] = "none";
                    BindDatatoAll();
                }
                else
                {
                    Response.Redirect("~/AccessDenied.aspx");
                }
            }
            else
            {
                Response.Redirect("~/AccessDenied.aspx");
            }
        }
        //*********************************************
        if (Request.QueryString["Poid"] != null && Convert.ToInt32(Request.QueryString["Currency"]) >= 2)//for International
        {
            string Pagepermission = "select PAGE_ID,PAGE_ADD,USERID,USERNAME as EmailID from USER_PERMISSION inner join LOGIN on USER_PERMISSION.USER_ID=LOGIN.USERID where USER_ID='" + Session["userid"].ToString() + "' and PAGE_ID=449";
            DataTable dt = DU.getdata(Pagepermission);
            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["PAGE_ADD"].ToString() == "True")
                {
                    BindPOImportTaxItemLevel();//for Imported    
                    Bind_DDLTaxGroup();
                    Bind_CustomDuty();//for CustomDuty;
                    Bind_CVD();//For CVD;
                    Bind_AdditionalDuty();//For Additional Duty;
                    lblFolioNo.Visible = true;
                    txtfolioNo.Visible = true;
                    generaltab.Style["display"] = "none";
                    calgeneral.Style["display"] = "none";
                    if (!IsPostBack)
                    {
                        Bind_CVD2();//for CVD2%;
                        Bind_CVD1();//for CVD1%;
                    }
                    BindDatatoAll();
                }
                else
                {
                    Response.Redirect("~/AccessDenied.aspx");
                }
            }
            else
            {
                Response.Redirect("~/AccessDenied.aspx");
            }
        }
    }
    protected void BindDatatoAll()
    {
        if (!IsPostBack)
        {            
            Bind_Currency();
            if (Request.QueryString["Poid"] != null)
            {
                hyperPoNumber.Attributes.Add("onclick", "OpenWindow(" + Request.QueryString["Poid"].ToString() + ");");
                BindPurchaseOrderDetails();
            }
            //*****Common Function*******
            //txtDate.Text = string.Format("{0:dd/MM/yyyy}", Convert.ToDateTime(System.DateTime.Now)).ToString();
            txtBillAddress.Text = "Communications Test Design India Pvt. Ltd 15,Sec-6, IMT Manesar, Gurgaon, Haryana-122051,India Phone- 0124-4748777";
            txtDeliveryAdd.Text = "Communications Test Design India Pvt. Ltd 15,Sec-6, IMT Manesar, Gurgaon, Haryana-122051,India Phone- 0124-4748777";
            txtPreparedBy.Text = "Sanjay Samal";
            txtCheckedBy.Text = "Vishnuchit Vats";
            txtSignatory.Text = "Anil Kumar Rai";
            Enable_TextBoxs();
            Bind_VoucherNo();
            AccountSettings.SetDate(form1);
            if (Request.QueryString["Currency"] != null)
            {
                HidCurrency.Value = Request.QueryString["Currency"].ToString();
            }
            //TxtPurchaseReceiveDate.Text = string.Format("{0:dd/MM/yyyy}", Convert.ToDateTime(System.DateTime.Now)).ToString();
            //For Creating the Log File.
            //PurchaseReceiveMain = "";
            //PurchaseReceiveMain = "Purchase Order No=" + hyperPoNumber.Text + ",Supplier=" + lblSupplier.Text + ",Voucher No=" + txtPrefix.Text + "/" + txtVoucher.Text + "/" + txtSuffix.Text +
              //  ",InvoiceDateOfSupplier=" + txtDate.Text + ",LeasedType=" + ddlleasedtype.SelectedItem.Text +
               // ",PaymentType=" + rbtCashCredit.SelectedItem.Text + ",Currency=" + ddlcurrency.SelectedItem.Text +
               // ",PurchaseReceiveDate=" + TxtPurchaseReceiveDate.Text + ",InvoiceNoOfSupplier=" + txtInvoiceNo.Text +
               // ",TaxGroup=" + ddlTaxGroup.SelectedItem.Text + ",TotalInvoiceValue=" + txtTotalInvoiceValue.Text + ",";
            //Creating Log for the Domestic Purchase Receive
            IP = Request.ServerVariables["REMOTE_ADDR"];
            PurchaseReceive = PurchaseReceiveMain + PurchaseReceiveDetails;
            Log.SetPurchaseOrderReceiveLogs(Session["userid"].ToString(), Session["username"].ToString(), CommonLog.Type.ActivityLog.ToString(), PurchaseReceive, "PurInvoiceWithItemLevel.aspx", IP, System.DateTime.Now.ToString());
        }
    }
    protected void BindPOImportTaxItemLevel()
    {
        strsql = "select currency_name from MAS_Currency where id='" + ddlcurrency.SelectedValue + "'";
        DataTable dt = DU.getdata(strsql);
        if (dt.Rows.Count > 0)
        {
            lblunitprice.Text = "(" + dt.Rows[0]["currency_name"].ToString() + ")";
            lblunitprice1.Text = "(" + dt.Rows[0]["currency_name"].ToString() + ")";
        }
        SqlParameter[] sparam = {
                                    new SqlParameter("@POID",Request.QueryString["Poid"].ToString())
                                };
        DataTable DTImportPoDetails = DU.getdatausingprocedure("USP_IVR_GetPoDetailsForPurchaseInvoice", sparam);
        if (DTImportPoDetails.Rows.Count > 0)
        {
            for (int i = 1; i <= DTImportPoDetails.Rows.Count; i++)
            {
                AddImportRows();
            }
            for (int j = 1; j <= DTImportPoDetails.Rows.Count; j++)
            {
                TextBox txtIpartno = (TextBox)tblImportItemLevel.Rows[j].FindControl("txtIpartno" + j.ToString());
                TextBox txtIdesc = (TextBox)tblImportItemLevel.Rows[j].FindControl("txtIdesc" + j.ToString());
                HiddenField hidIUnitPrice = (HiddenField)tblImportItemLevel.Rows[j].FindControl("hidIUnitPrice" + j.ToString());
                HiddenField hidIQty = (HiddenField)tblImportItemLevel.Rows[j].FindControl("hidIQty" + j.ToString());
                HiddenField hidInternationalQty = (HiddenField)tblImportItemLevel.Rows[j].FindControl("hidInternationalQty" + j.ToString());
                TextBox txtIUnitPrice = (TextBox)tblImportItemLevel.Rows[j].FindControl("txtIUnitPrice" + j.ToString());
                TextBox txtIQty = (TextBox)tblImportItemLevel.Rows[j].FindControl("txtIQty" + j.ToString());
                HiddenField issueqty = (HiddenField)tblImportItemLevel.Rows[j].FindControl("issueqty" + j.ToString());
                HiddenField hidpartno = (HiddenField)tblImportItemLevel.Rows[j].FindControl("hidIpartno" + j.ToString());
                HiddenField hidUOMID = (HiddenField)tblImportItemLevel.Rows[j].FindControl("hidUOMID" + j.ToString());
                HiddenField hidRateInc = (HiddenField)tblImportItemLevel.Rows[j].FindControl("hidRateInc" + j.ToString());

                txtIpartno.Text = DTImportPoDetails.Rows[j - 1]["ITMCODE"].ToString();
                txtIdesc.Text = DTImportPoDetails.Rows[j - 1]["ITEMNAME"].ToString();
                hidIUnitPrice.Value = DTImportPoDetails.Rows[j - 1]["PORATE"].ToString();
                hidIQty.Value = DTImportPoDetails.Rows[j - 1]["OrderQty"].ToString();
                hidpartno.Value = DTImportPoDetails.Rows[j - 1]["ItemId"].ToString();
                issueqty.Value = DTImportPoDetails.Rows[j - 1]["ISSUEQTY"].ToString();
                hidUOMID.Value = DTImportPoDetails.Rows[j - 1]["UOMID"].ToString();
                hidRateInc.Value = DTImportPoDetails.Rows[j - 1]["RateInclTax"].ToString();
                if (hidIUnitPrice.Value != "")
                {
                    txtIUnitPrice.Text = Convert.ToDouble(hidIUnitPrice.Value).ToString();
                }
                if (hidIQty.Value != "")
                {
                    txtIQty.Text = Convert.ToDouble(hidIQty.Value).ToString();
                    hidInternationalQty.Value = Convert.ToDouble(hidIQty.Value).ToString();
                }
                //txtIQty.Text=
                txtIUnitPrice.ToolTip = "Unit Price(" + string.Format("{0:0.00}", Convert.ToDouble(hidIUnitPrice.Value)) + ")";
                txtIQty.ToolTip = "Qty(" + string.Format("{0:0.00}", Convert.ToDouble(DTImportPoDetails.Rows[j - 1]["ITEMQTY"].ToString())) + ")/ Balance Qty(" + string.Format("{0:0.00}", Convert.ToDouble(hidIQty.Value)) + ")";
                if (!IsPostBack)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Calculation", "UnitPrice();InvoiceValue();CustomeDuty();", true);
                }
                //For Log of the Item.
                PurchaseReceiveDetails += "PartNO=" + txtIpartno.Text + ",Desciption=" + txtIdesc.Text + ",UnitPrice=" + hidIUnitPrice.Value + ",Qty=" + hidIQty.Value + ",Freight=" + txtfreight.Text + ",Packaging=" + txtpackaging.Text;
            }
        }
        //For International
        string str = "select Countryid,Short_Name+' [ '+Countryname+' ]' as Short_Name from Country where isActive='TRUE'";
        DataTable dtcountry = DU.getdata(str);
        for (int j = 1; j < tblImportItemLevel.Rows.Count; j++)
        {
            DropDownList ddl = (DropDownList)tblImportItemLevel.Rows[j].FindControl("ddlIcoo" + j.ToString());
            if (dtcountry.Rows.Count > 0)
            {
                ddl.DataSource = dtcountry;
                ddl.DataTextField = "Short_Name";
                ddl.DataValueField = "Countryid";
                ddl.DataBind();
                ddl.Items.Insert(0, new ListItem("None", "0"));
            }
        }
    }
    protected void Bind_CustomDuty()
    {
        string customduty = "select ACC_TAXSUBCLASS.SUBCLASSID as SUBCLASSID,ACC_TAXSUBCLASS.SUBCLASSNAME as SUBCLASSNAME,TAXRATE from ACC_TAXSUBCLASS inner join ACC_TAXMASTER on ACC_TAXMASTER.SUBCLASSID=ACC_TAXSUBCLASS.SUBCLASSID inner join ACC_TAXDETAILS on ACC_TAXDETAILS.TAXMASTERID=ACC_TAXMASTER.TAXMASTERID where ACC_TAXMASTER.MAINCLASSID='" + ddlTaxGroup.SelectedValue + "' and ACC_TAXSUBCLASS.SUBCLASSNAME like 'Basic %'";
        DataTable dtcustom = DU.getdata(customduty);
        for (int k = 1; k < tblImportItemLevel.Rows.Count; k++)
        {
            DropDownList ddlcustom = (DropDownList)tblImportItemLevel.Rows[k].FindControl("ddlIBasicCust" + k.ToString());
            if (dtcustom.Rows.Count > 0)
            {
                ddlcustom.DataSource = dtcustom;
                ddlcustom.DataTextField = "SUBCLASSNAME";
                ddlcustom.DataValueField = "TAXRATE";
                ddlcustom.DataBind();
                ddlcustom.Items.Insert(0, new ListItem(" None ", "0"));
            }
        }
    }
    protected void Bind_Currency()
    {
        strsql = " select * from MAS_Currency";
        DataTable dtcur = DU.getdata(strsql);
        if (dtcur.Rows.Count > 0)
        {
            ddlcurrency.DataSource = dtcur;
            ddlcurrency.DataTextField = "currency_name";
            ddlcurrency.DataValueField = "id";
            ddlcurrency.DataBind();
            ddlcurrency.Items.Insert(0, new ListItem("- Select Currency -", "0"));
            ddlcurrency.Enabled = false;
        }
    }
    protected void Bind_DDLTaxGroup()//bind tax group
    {
        if (Request.QueryString["Currency"] == "1")
        {
            DataTable DT = DU.getdatausingprocedure("USP_ACC_GetPurchaseMainClass");
            if (DT.Rows.Count > 0)
            {
                ddlTaxGroup.DataSource = DT;
                ddlTaxGroup.DataTextField = "MAINCLASSNAME";
                ddlTaxGroup.DataValueField = "MAINCLASSID";
                ddlTaxGroup.DataBind();
                ddlTaxGroup.Items.Insert(0, new ListItem("-Select Tax Group-", "0"));
                //ddlTaxGroup.SelectedValue = "0";
            }
            //Datatable for LocalPurchase
            DataTable DTLocalPurchase = new DataTable();
            DTLocalPurchase = DU.getdata("select SUBCLASSID,SUBCLASSNAME,ISNULL(DEFTAXRATE,'0') as TAXRATE from UVW_ACC_TaxMaster where mainclassid='" + DT.Rows[0]["MAINCLASSID"].ToString() + "'");
            if (DTLocalPurchase.Rows.Count > 0)
            {
                int j = 1;
                for (int i = 0; i < DTLocalPurchase.Rows.Count; i++)
                {
                    hidpurchaseCounter.Value = j.ToString();
                    HtmlTableRow htmlrow = new HtmlTableRow();
                    HtmlTableCell htmlcell1 = new HtmlTableCell();
                    TextBox txtSubClassID = new TextBox();
                    txtSubClassID.ID = "txtSubClassID" + j;
                    htmlcell1.Controls.Add(txtSubClassID);

                    HtmlTableCell htmlcell2 = new HtmlTableCell();
                    TextBox txtSubClassName = new TextBox();
                    txtSubClassName.ID = "txtSubClassName" + j;
                    htmlcell2.Controls.Add(txtSubClassName);

                    HtmlTableCell htmlcell3 = new HtmlTableCell();
                    TextBox txtSubTAX = new TextBox();
                    txtSubTAX.ID = "txtSubTAX" + j;
                    htmlcell3.Controls.Add(txtSubTAX);


                    htmlrow.Cells.Add(htmlcell1);
                    htmlrow.Cells.Add(htmlcell2);
                    htmlrow.Cells.Add(htmlcell3);
                    tblLocalPurchase.Rows.Add(htmlrow);
                    j++;
                }
                for (int k = 1; k <= DTLocalPurchase.Rows.Count; k++)
                {
                    TextBox txtSubClassID = (TextBox)tblLocalPurchase.Rows[k].FindControl("txtSubClassID" + k.ToString());
                    TextBox txtSubClassName = (TextBox)tblLocalPurchase.Rows[k].FindControl("txtSubClassName" + k.ToString());
                    TextBox txtTaxRate = (TextBox)tblLocalPurchase.Rows[k].FindControl("txtSubTAX" + k.ToString());

                    txtSubClassID.Text = DTLocalPurchase.Rows[k - 1]["SUBCLASSID"].ToString();
                    txtSubClassName.Text = DTLocalPurchase.Rows[k - 1]["SUBCLASSNAME"].ToString();
                    txtTaxRate.Text = DTLocalPurchase.Rows[k - 1]["TAXRATE"].ToString();
                }
            }
            //Datatable For URDPurchase
            DataTable DTURDPurchase = new DataTable();
            DTURDPurchase = DU.getdata("select SUBCLASSID,SUBCLASSNAME,ISNULL(DEFTAXRATE,'0') as TAXRATE from UVW_ACC_TaxMaster where mainclassid='" + DT.Rows[1]["MAINCLASSID"].ToString() + "'");
            if (DTURDPurchase.Rows.Count > 0)
            {
                int j = 1;
                for (int i = 0; i < DTURDPurchase.Rows.Count; i++)
                {
                    hidURDpurchaseCounter.Value = j.ToString();
                    HtmlTableRow htmlrow = new HtmlTableRow();
                    HtmlTableCell htmlcell1 = new HtmlTableCell();
                    TextBox txtURDSubClassID = new TextBox();
                    txtURDSubClassID.ID = "txtURDSubClassID" + j;
                    htmlcell1.Controls.Add(txtURDSubClassID);

                    HtmlTableCell htmlcell2 = new HtmlTableCell();
                    TextBox txtURDSubClassName = new TextBox();
                    txtURDSubClassName.ID = "txtURDSubClassName" + j;
                    htmlcell2.Controls.Add(txtURDSubClassName);

                    HtmlTableCell htmlcell3 = new HtmlTableCell();
                    TextBox txtURDSubTAX = new TextBox();
                    txtURDSubTAX.ID = "txtURDSubTAX" + j;
                    htmlcell3.Controls.Add(txtURDSubTAX);


                    htmlrow.Cells.Add(htmlcell1);
                    htmlrow.Cells.Add(htmlcell2);
                    htmlrow.Cells.Add(htmlcell3);
                    tblURDPurchase.Rows.Add(htmlrow);
                    j++;
                }
                for (int k = 1; k <= DTURDPurchase.Rows.Count; k++)
                {
                    TextBox txtSubClassID = (TextBox)tblURDPurchase.Rows[k].FindControl("txtURDSubClassID" + k.ToString());
                    TextBox txtSubClassName = (TextBox)tblURDPurchase.Rows[k].FindControl("txtURDSubClassName" + k.ToString());
                    TextBox txtTaxRate = (TextBox)tblURDPurchase.Rows[k].FindControl("txtURDSubTAX" + k.ToString());
                    txtSubClassID.Text = DTURDPurchase.Rows[k - 1]["SUBCLASSID"].ToString();
                    txtSubClassName.Text = DTURDPurchase.Rows[k - 1]["SUBCLASSNAME"].ToString();
                    txtTaxRate.Text = DTURDPurchase.Rows[k - 1]["TAXRATE"].ToString();
                }
            }
            //Datatable for InterStatePurchase
            DataTable DTInterStatePurchase = new DataTable();
            DTInterStatePurchase = DU.getdata("select SUBCLASSID,SUBCLASSNAME,ISNULL(DEFTAXRATE,'0') as TAXRATE from UVW_ACC_TaxMaster where mainclassid='" + DT.Rows[2]["MAINCLASSID"].ToString() + "'");
            if (DTInterStatePurchase.Rows.Count > 0)
            {
                int j = 1;
                for (int i = 0; i < DTInterStatePurchase.Rows.Count; i++)
                {
                    hidInterStatepurchaseCounter.Value = j.ToString();
                    HtmlTableRow htmlrow = new HtmlTableRow();
                    HtmlTableCell htmlcell1 = new HtmlTableCell();
                    TextBox txtInterstateSubClassID = new TextBox();
                    txtInterstateSubClassID.ID = "txtInterstateSubClassID" + j;
                    htmlcell1.Controls.Add(txtInterstateSubClassID);

                    HtmlTableCell htmlcell2 = new HtmlTableCell();
                    TextBox txtInterstateSubClassName = new TextBox();
                    txtInterstateSubClassName.ID = "txtInterstateSubClassName" + j;
                    htmlcell2.Controls.Add(txtInterstateSubClassName);

                    HtmlTableCell htmlcell3 = new HtmlTableCell();
                    TextBox txtInterstateSubTAX = new TextBox();
                    txtInterstateSubTAX.ID = "txtInterstateSubTAX" + j;
                    htmlcell3.Controls.Add(txtInterstateSubTAX);


                    htmlrow.Cells.Add(htmlcell1);
                    htmlrow.Cells.Add(htmlcell2);
                    htmlrow.Cells.Add(htmlcell3);
                    tblInterStatePurchase.Rows.Add(htmlrow);
                    j++;
                }
                for (int k = 1; k <= DTInterStatePurchase.Rows.Count; k++)
                {
                    TextBox txtSubClassID = (TextBox)tblInterStatePurchase.Rows[k].FindControl("txtInterstateSubClassID" + k.ToString());
                    TextBox txtSubClassName = (TextBox)tblInterStatePurchase.Rows[k].FindControl("txtInterstateSubClassName" + k.ToString());
                    TextBox txtTaxRate = (TextBox)tblInterStatePurchase.Rows[k].FindControl("txtInterstateSubTAX" + k.ToString());
                    txtSubClassID.Text = DTInterStatePurchase.Rows[k - 1]["SUBCLASSID"].ToString();
                    txtSubClassName.Text = DTInterStatePurchase.Rows[k - 1]["SUBCLASSNAME"].ToString();
                    txtTaxRate.Text = DTInterStatePurchase.Rows[k - 1]["TAXRATE"].ToString();
                }
            }
        }
        else
        {
            //DataTable DT = DU.getdata("SELECT  MAINCLASSID,MAINCLASSNAME FROM ACC_TAXMAINCLASS WHERE(MAINCLASSID = 43)AND(TAXTYPEID = 14)");
            DataTable DT = DU.getdata("SELECT  MAINCLASSID,MAINCLASSNAME FROM ACC_TAXMAINCLASS WHERE(MAINCLASSID =45)AND(TAXTYPEID=14)");
            if (DT.Rows.Count > 0)
            {
                ddlTaxGroup.DataSource = DT;
                ddlTaxGroup.DataTextField = "MAINCLASSNAME";
                ddlTaxGroup.DataValueField = "MAINCLASSID";
                ddlTaxGroup.DataBind();
                //ddlTaxGroup.Items.Insert(0, new ListItem("-select Tax Group-", "0"));
                ddlTaxGroup.Items.FindByText("Import").Selected = true;
            }
        }
    }
    protected void BindPurchaseLedger(DropDownList ddl)//bind purchase ledger
    {
        DataTable DT = DU.getdatausingprocedure("USP_IVR_GetPurchaseLedgerforPurchaseInvoice");
        if (DT.Rows.Count > 0)
        {
            ddl.DataSource = DT;
            ddl.DataTextField = "LNAME";
            ddl.DataValueField = "LID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("- Select Ledger -", "0"));
        }
        else
        {
            ddl.Items.Clear();
        }
    } 
    protected void BindTaxLedger(DropDownList ddl)//bind Tax ledger
    {
        DataTable DT = DU.getdatausingprocedure("USP_IVR_GetTaxLedgerforPurchaseInvoice");
        if (DT.Rows.Count > 0)
        {
            ddl.DataSource = DT;
            ddl.DataTextField = "Lname";
            ddl.DataValueField = "LID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("- Select Ledger -", "0"));
        }
        else
        {
            ddl.Items.Clear();
        }
    }
    protected void ddlTaxGroup_SelectedIndexChanged(object sender, EventArgs e)
    {
        //if (ddlTaxGroup.SelectedValue != "0" && ddlTaxGroup.SelectedValue != "2")
        //{
        //    string strvattin = "select IsNull(lR.VATTIN,'') as TinNo from ACC_LEDREGDETAILS lR inner join ACC_LEDMAST LM on lR.LID=LM.LID where LM.LID=" + hidSupplierID.Value;
        //    DataTable DTTin = DU.getdata(strvattin);
        //    if (DTTin.Rows.Count > 0)
        //    {
        //        if (DTTin.Rows[0]["TinNo"].ToString() == "")
        //        {
        //            MPEAlert.Show();
        //            return;
        //        }
        //    }
        //}
        //strsql = "select SUBCLASSID,SUBCLASSNAME from UVW_ACC_TaxMaster where mainclassid='" + ddlTaxGroup.SelectedValue + "'";
        //DataTable DT = DU.getdata(strsql);
        //for (int i = 1; i < tblTaxItemLevel.Rows.Count; i++)
        //{
        //    DropDownList ddl = (DropDownList)tblTaxItemLevel.Rows[i].FindControl("ddlsalestax" + i.ToString());
        //    if (DT.Rows.Count > 0)
        //    {
        //        ddl.Items.Clear();
        //        ddl.DataSource = DT;
        //        ddl.DataTextField = "SUBCLASSNAME";
        //        ddl.DataValueField = "SUBCLASSID";
        //        ddl.DataBind();
        //        ddl.Items.Insert(0, new ListItem("- Select Tax -", "0"));
        //    }
        //}        
    }
    protected void Bind_AdditionalDuty()
    {
        string AddDuty = "select ACC_TAXSUBCLASS.SUBCLASSID as SUBCLASSID,ACC_TAXSUBCLASS.SUBCLASSNAME as SUBCLASSNAME,TAXRATE from ACC_TAXSUBCLASS inner join ACC_TAXMASTER on ACC_TAXMASTER.SUBCLASSID=ACC_TAXSUBCLASS.SUBCLASSID inner join ACC_TAXDETAILS on ACC_TAXDETAILS.TAXMASTERID=ACC_TAXMASTER.TAXMASTERID where ACC_TAXMASTER.MAINCLASSID='" + ddlTaxGroup.SelectedValue + "' and ACC_TAXSUBCLASS.SUBCLASSNAME like 'Add.%'";
        DataTable DtAdditional = DU.getdata(AddDuty);
        for (int i = 1; i < tblImportItemLevel.Rows.Count; i++)
        {
            DropDownList ddlAddtionalDuty = (DropDownList)tblImportItemLevel.Rows[i].FindControl("ddlIAddDuty" + i.ToString());
            if (DtAdditional.Rows.Count > 0)
            {
                ddlAddtionalDuty.DataSource = DtAdditional;
                ddlAddtionalDuty.DataTextField = "SUBCLASSNAME";
                ddlAddtionalDuty.DataValueField = "TAXRATE";
                ddlAddtionalDuty.DataBind();
                ddlAddtionalDuty.Items.Insert(0, new ListItem(" None ", "0"));
            }
        }
    }
    protected void Bind_CVD()
    {
        string CVD = "select ACC_TAXSUBCLASS.SUBCLASSID as SUBCLASSID,ACC_TAXSUBCLASS.SUBCLASSNAME as SUBCLASSNAME,TAXRATE from ACC_TAXSUBCLASS inner join ACC_TAXMASTER on ACC_TAXMASTER.SUBCLASSID=ACC_TAXSUBCLASS.SUBCLASSID inner join ACC_TAXDETAILS on ACC_TAXDETAILS.TAXMASTERID=ACC_TAXMASTER.TAXMASTERID where ACC_TAXMASTER.MAINCLASSID='" + ddlTaxGroup.SelectedValue + "' and ACC_TAXSUBCLASS.SUBCLASSNAME like 'CVD %'";
        DataTable dtCVD = DU.getdata(CVD);
        for (int k = 1; k < tblImportItemLevel.Rows.Count; k++)
        {
            DropDownList ddlCVD = (DropDownList)tblImportItemLevel.Rows[k].FindControl("ddlICVD" + k.ToString());
            if (dtCVD.Rows.Count > 0)
            {
                ddlCVD.DataSource = dtCVD;
                ddlCVD.DataTextField = "SUBCLASSNAME";
                ddlCVD.DataValueField = "TAXRATE";
                ddlCVD.DataBind();
                ddlCVD.Items.Insert(0, new ListItem(" None ", "0"));
            }
        }
    }
    protected void Bind_CVD2()
    {
        for (int k = 1; k < tblImportItemLevel.Rows.Count; k++)
        {
            DropDownList ddlCVD2 = (DropDownList)tblImportItemLevel.Rows[k].FindControl("ddleducessoncvd" + k.ToString());
            ListItem lstitem1 = new ListItem();
            lstitem1.Text = "None";
            lstitem1.Value = "0";

            ListItem lstitem2 = new ListItem();
            lstitem2.Text = "2%";
            lstitem2.Value = "2";

            //DdlStatus.Items.Add(lstitem1);
            ddlCVD2.Items.Add(lstitem1);
            ddlCVD2.Items.Add(lstitem2);
        }
    }
    protected void Bind_CVD1()
    {
        for (int k = 1; k < tblImportItemLevel.Rows.Count; k++)
        {
            DropDownList ddlCVD1 = (DropDownList)tblImportItemLevel.Rows[k].FindControl("ddlHeducessoncvd" + k.ToString());
            ListItem lstitem1 = new ListItem();
            lstitem1.Text = "None";
            lstitem1.Value = "0";

            ListItem lstitem2 = new ListItem();
            lstitem2.Text = "1%";
            lstitem2.Value = "1";

            //DdlStatus.Items.Add(lstitem1);
            ddlCVD1.Items.Add(lstitem1);
            ddlCVD1.Items.Add(lstitem2);
        }
    }
    protected void ResetTaxRateForAllFormat()//a common function reset tax rate on hiddenfield according tax group
    {
        for (int i = 1; i < tblTaxItemLevel.Rows.Count; i++)
        {
            HiddenField hidTaxRate = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidsalestax" + i.ToString());
            hidTaxRate.Value = "";
        }
    }
    protected void BindTaxForAllFormat()//a common function bind tax type according transaction fromat
    {
        for (int i = 1; i < tblTaxItemLevel.Rows.Count; i++)
        {
            DropDownList ddl = (DropDownList)tblTaxItemLevel.Rows[i].FindControl("ddlsalestax" + i.ToString());
            BindTaxSubGroup(ddl);
        }
    }
    protected void AddRows()
    {
        tblItemsCounter++;
        HtmlTableRow htmlrow = new HtmlTableRow();

        HtmlTableCell htmlcell1 = new HtmlTableCell();
        htmlcell1.Width = "8%";
        TextBox txtpartno = new TextBox();
        txtpartno.ID = "txtpartno" + tblItemsCounter.ToString();
        txtpartno.Width = 80;
        txtpartno.CssClass = "labelText";
        txtpartno.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        //txtpartno.Attributes.Add("onblur", "return Calculate();");
        txtpartno.Style["background-color"] = "#C8D0D4";
        txtpartno.ToolTip = "Part No";
        txtpartno.TabIndex = 1;
        HiddenField hiPartId = new HiddenField();
        hiPartId.ID = "hiPartId" + tblItemsCounter.ToString();
        htmlcell1.Controls.Add(txtpartno);
        htmlcell1.Controls.Add(hiPartId);

        HtmlTableCell htmlcell2 = new HtmlTableCell();
        htmlcell2.Width = "12%";
        TextBox txtdesc = new TextBox();
        txtdesc.ID = "txtdesc" + tblItemsCounter.ToString();
        txtdesc.Width = 150;
        txtdesc.CssClass = "labelText";
        txtdesc.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        //txtdesc.Attributes.Add("onblur", "return Calculate();");
        txtdesc.Style["background-color"] = "#C8D0D4";
        txtdesc.TabIndex = 2;
        //txtdesc.ToolTip = "Part Description";
        HiddenField hidescid = new HiddenField();
        hidescid.ID = "hidescid" + tblItemsCounter.ToString();

        htmlcell2.Controls.Add(txtdesc);
        htmlcell2.Controls.Add(hidescid);

        HtmlTableCell htmlcell3 = new HtmlTableCell();
        htmlcell3.Width = "8%";
        TextBox txtunitprice = new TextBox();
        txtunitprice.ID = "txtunitprice" + tblItemsCounter.ToString();
        txtunitprice.Width = 60;
        txtunitprice.CssClass = "labelText";
        txtunitprice.Attributes.Add("onKeyPress", "return isNumberKey(this.id,event)");
        txtunitprice.Attributes.Add("onblur", "return Calculate(" + tblItemsCounter + ");");
        txtunitprice.Style["text-align"] = "right";
        txtunitprice.TabIndex = 3;
        //txtunitprice.ToolTip = "Unit price";
        HiddenField hidunitprice = new HiddenField();
        hidunitprice.ID = "hidunitprice" + tblItemsCounter.ToString();
        HiddenField hidUOMID = new HiddenField();
        hidUOMID.ID = "hidUOMID" + tblItemsCounter.ToString();
        htmlcell3.Controls.Add(txtunitprice);
        htmlcell3.Controls.Add(hidunitprice);
        htmlcell3.Controls.Add(hidUOMID);

        HtmlTableCell htmlcell4 = new HtmlTableCell();
        htmlcell4.Width = "8%";
        TextBox txtqty = new TextBox();
        txtqty.ID = "txtqty" + tblItemsCounter.ToString();
        txtqty.Width = 55;
        txtqty.CssClass = "labelText";
        //txtqty.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        //txtqty.Style["background-color"] = "lightGray";
        txtqty.Style["text-align"] = "right";
        txtqty.Attributes.Add("onKeyPress", "return isNumber(event)");
        txtqty.Attributes.Add("onblur", "return Calculate(" + tblItemsCounter + ");");
        txtqty.TabIndex = 4;
        HiddenField hidqty = new HiddenField();
        hidqty.ID = "hidqty" + tblItemsCounter.ToString();
        HiddenField hidDoqty = new HiddenField();
        hidDoqty.ID = "hidDoqty" + tblItemsCounter.ToString();
        HiddenField issueqty = new HiddenField();
        issueqty.ID = "issueqty" + tblItemsCounter.ToString();
        htmlcell4.Controls.Add(txtqty);
        htmlcell4.Controls.Add(issueqty);
        htmlcell4.Controls.Add(hidDoqty);
        htmlcell4.Controls.Add(hidqty);

        //HtmlTableCell htmlcell13 = new HtmlTableCell();
        //Button btnQty = new Button();
        //btnQty.ID = "btnQty" + tblItemsCounter.ToString();
        //btnQty.Width = Unit.Percentage(99);
        //btnQty.CssClass = "button";
        //btnQty.Text = "...";
        //HiddenField hidLocationId = new HiddenField();
        //hidLocationId.ID = "hidLocationId" + tblItemsCounter.ToString();
        //htmlcell13.Controls.Add(btnQty);
        //htmlcell13.Controls.Add(hidLocationId);

        HtmlTableCell htmlcell5 = new HtmlTableCell();
        htmlcell5.Width = "8%";
        TextBox txtsubamount = new TextBox();
        txtsubamount.ID = "txtsubamount" + tblItemsCounter.ToString();
        txtsubamount.Width = 50;
        txtsubamount.CssClass = "labelText";
        txtsubamount.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtsubamount.Attributes.Add("onblur", "return Calculate(" + tblItemsCounter + ");");
        txtsubamount.Style["background-color"] = "#C8D0D4";
        txtsubamount.Style["text-align"] = "right";
        txtsubamount.ToolTip = "Sub Amount";
        txtsubamount.TabIndex = 5;
        HiddenField hidsubamt = new HiddenField();
        hidsubamt.ID = "hidsubamt" + tblItemsCounter.ToString();
        HiddenField hidRateIncTax = new HiddenField();
        hidRateIncTax.ID = "hidRateIncTax" + tblItemsCounter.ToString();
        htmlcell5.Controls.Add(txtsubamount);
        htmlcell5.Controls.Add(hidsubamt);
        htmlcell5.Controls.Add(hidRateIncTax);

        HtmlTableCell htmlcell6 = new HtmlTableCell();
        htmlcell6.Width = "8%";
        DropDownList ddlsalestax = new DropDownList();
        ddlsalestax.ID = "ddlsalestax" + tblItemsCounter.ToString();
        ddlsalestax.Width = 70;
        ddlsalestax.CssClass = "dropdown";
        ddlsalestax.ToolTip = "Sales Tax(VAT/CST)";
        ddlsalestax.Attributes.Add("onchange", "setdefaultvalue(this.value," + tblItemsCounter + ",this.selectedIndex);");
        //ddlsalestax.Attributes.Add("onblur", "return Calculate();");
        ddlsalestax.TabIndex = 6;
        //txtsubamount.Style["text-align"] = "right";
        //ddlsalestax.AutoPostBack = true;
        //ddlsalestax.SelectedIndexChanged += new EventHandler(ddlsalestax_SelectedIndexChanged);
        HiddenField hidsalestax = new HiddenField();
        hidsalestax.ID = "hidsalestax" + tblItemsCounter.ToString();
        HiddenField hidsalestaxID = new HiddenField();
        hidsalestaxID.ID = "hidsalestaxID" + tblItemsCounter.ToString();
        htmlcell6.Controls.Add(hidsalestaxID);
        htmlcell6.Controls.Add(ddlsalestax);
        htmlcell6.Controls.Add(hidsalestax);

        HtmlTableCell htmlcell7 = new HtmlTableCell();
        htmlcell7.Width = "8%";
        TextBox txtvatcstamt = new TextBox();
        txtvatcstamt.ID = "txtvatcstamt" + tblItemsCounter.ToString();
        txtvatcstamt.Width = 60;
        txtvatcstamt.CssClass = "labelText";
        txtvatcstamt.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtvatcstamt.Attributes.Add("onblur", "return Calculate(" + tblItemsCounter + ");");
        txtvatcstamt.Style["background-color"] = "#C8D0D4";
        txtvatcstamt.Style["text-align"] = "right";
        txtvatcstamt.TabIndex = 7;
        txtvatcstamt.ToolTip = "Sales Tax Amount";
        HiddenField hidvatcst = new HiddenField();
        hidvatcst.ID = "hidvatcst" + tblItemsCounter.ToString();
        htmlcell7.Controls.Add(txtvatcstamt);
        htmlcell7.Controls.Add(hidvatcst);

        HtmlTableCell htmlcell8 = new HtmlTableCell();
        htmlcell8.Width = "8%";
        TextBox txtfreight = new TextBox();
        txtfreight.ID = "txtfreight" + tblItemsCounter.ToString();
        txtfreight.Width = 50;
        txtfreight.CssClass = "labelText";
        txtfreight.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtfreight.Attributes.Add("onblur", "return Calculate(" + tblItemsCounter + ");");
        txtfreight.Style["background-color"] = "#C8D0D4";
        txtfreight.Style["text-align"] = "right";
        txtfreight.ToolTip = "Freight";
        txtfreight.TabIndex = 10;
        HiddenField hidfreight = new HiddenField();
        hidfreight.ID = "hidfreight" + tblItemsCounter.ToString();
        htmlcell8.Controls.Add(txtfreight);
        htmlcell8.Controls.Add(hidfreight);

        HtmlTableCell htmlcell9 = new HtmlTableCell();
        htmlcell9.Width = "8%";
        TextBox txtpackaging = new TextBox();
        txtpackaging.ID = "txtpackaging" + tblItemsCounter.ToString();
        txtpackaging.Width = 55;
        txtpackaging.CssClass = "labelText";
        txtpackaging.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtpackaging.Attributes.Add("onblur", "return Calculate(" + tblItemsCounter + ");");
        txtpackaging.Style["background-color"] = "#C8D0D4";
        txtpackaging.ToolTip = "Packaging";
        txtpackaging.Style["text-align"] = "right";
        txtpackaging.TabIndex = 11;
        HiddenField hidpacking = new HiddenField();
        hidpacking.ID = "hidpacking" + tblItemsCounter.ToString();
        htmlcell9.Controls.Add(txtpackaging);
        htmlcell9.Controls.Add(hidpacking);

        HtmlTableCell htmlcell10 = new HtmlTableCell();
        htmlcell10.Width = "8%";
        TextBox txtinsurance = new TextBox();
        txtinsurance.ID = "txtinsurance" + tblItemsCounter.ToString();
        txtinsurance.Width = 55;
        txtinsurance.CssClass = "labelText";
        txtinsurance.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtinsurance.Attributes.Add("onblur", "return Calculate(" + tblItemsCounter + ");");
        txtinsurance.Style["background-color"] = "#C8D0D4";
        txtinsurance.Style["text-align"] = "right";
        txtinsurance.ToolTip = "Insurance";
        txtinsurance.TabIndex = 12;
        HiddenField hidinsurance = new HiddenField();
        hidinsurance.ID = "hidinsurance" + tblItemsCounter.ToString();
        htmlcell10.Controls.Add(txtinsurance);
        htmlcell10.Controls.Add(hidinsurance);

        HtmlTableCell htmlcell11 = new HtmlTableCell();
        htmlcell11.Width = "8%";
        TextBox txttotallanded = new TextBox();
        txttotallanded.ID = "txttotallanded" + tblItemsCounter.ToString();
        txttotallanded.Width = 55;
        txttotallanded.CssClass = "labelText";
        txttotallanded.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txttotallanded.Attributes.Add("onblur", "return Calculate(" + tblItemsCounter + ");");
        txttotallanded.Style["background-color"] = "#C8D0D4";
        txttotallanded.Style["text-align"] = "right";
        txttotallanded.ToolTip = "Total Landed Cost";
        txttotallanded.TabIndex = 13;
        HiddenField hidtotallanded = new HiddenField();
        hidtotallanded.ID = "hidtotallanded" + tblItemsCounter.ToString();
        htmlcell11.Controls.Add(txttotallanded);
        htmlcell11.Controls.Add(hidtotallanded);

        HtmlTableCell htmlcell12 = new HtmlTableCell();
        htmlcell12.Width = "8%";
        htmlcell12.Style["display"] = "none";
        TextBox txttotalinventcost = new TextBox();
        txttotalinventcost.ID = "txttotalinventcost" + tblItemsCounter.ToString();
        txttotalinventcost.Width = 55;
        txttotalinventcost.CssClass = "labelText";
        txttotalinventcost.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txttotalinventcost.Attributes.Add("onblur", "return Calculate(" + tblItemsCounter + ");");
        txttotalinventcost.Style["background-color"] = "#C8D0D4";
        txttotalinventcost.Style["text-align"] = "right";
        txttotalinventcost.TabIndex = 14;
        txttotalinventcost.ToolTip = "Total Inventory Cost";
        HiddenField hidtotalinventcost = new HiddenField();
        hidtotalinventcost.ID = "hidtotalinventcost" + tblItemsCounter.ToString();
        htmlcell12.Controls.Add(txttotalinventcost);
        htmlcell12.Controls.Add(hidtotalinventcost);

        HtmlTableCell htmlcell13 = new HtmlTableCell();
        htmlcell13.Width = "8%";
        TextBox txtServiceTax = new TextBox();
        txtServiceTax.ID = "txtServiceTax" + tblItemsCounter.ToString();
        txtServiceTax.Width = 55;
        txtServiceTax.CssClass = "labelText";
        txtServiceTax.Attributes.Add("onKeyPress", "return isNumberKey(this.id,event)");
        txtServiceTax.Attributes.Add("onfocus", "if(this.value=='0.00') this.value='';");
        txtServiceTax.Attributes.Add("onblur", "ServiceTaxAmount(" + tblItemsCounter + ");");
        txtServiceTax.Style["text-align"] = "right";
        txtServiceTax.TabIndex = 8;
        txtServiceTax.ToolTip = "Service Tax";
        htmlcell13.Controls.Add(txtServiceTax);

        HtmlTableCell htmlcell14 = new HtmlTableCell();
        htmlcell14.Width = "8%";
        TextBox txtServiceTaxAmount = new TextBox();
        txtServiceTaxAmount.ID = "txtServiceTaxAmount" + tblItemsCounter.ToString();
        txtServiceTaxAmount.Width = 50;
        txtServiceTaxAmount.CssClass = "labelText";
        txtServiceTaxAmount.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        //txtServiceTaxAmount.Attributes.Add("onblur", "retrun SalestaxAmount();");        
        txtServiceTaxAmount.Style["text-align"] = "right";
        txtServiceTaxAmount.Style["background-color"] = "#C8D0D4";
        txtServiceTaxAmount.TabIndex = 9;
        txtServiceTaxAmount.ToolTip = "Service Tax Amount";
        htmlcell14.Controls.Add(txtServiceTaxAmount);

        htmlrow.Cells.Add(htmlcell1);
        htmlrow.Cells.Add(htmlcell2);
        htmlrow.Cells.Add(htmlcell3);
        htmlrow.Cells.Add(htmlcell4);
        htmlrow.Cells.Add(htmlcell5);
        htmlrow.Cells.Add(htmlcell6);
        htmlrow.Cells.Add(htmlcell7);
        htmlrow.Cells.Add(htmlcell13);
        htmlrow.Cells.Add(htmlcell14);
        htmlrow.Cells.Add(htmlcell8);
        htmlrow.Cells.Add(htmlcell9);
        htmlrow.Cells.Add(htmlcell10);
        htmlrow.Cells.Add(htmlcell11);
        htmlrow.Cells.Add(htmlcell12);

        tblTaxItemLevel.Rows.Add(htmlrow);
        hidControlTblItems.Value = tblItemsCounter.ToString();
    }
    protected void AddImportRows()
    {
        tblImportCounter++;
        HtmlTableRow htmlrow = new HtmlTableRow();
        #region
        HtmlTableCell htmlcell1 = new HtmlTableCell();
        TextBox txtIpartno = new TextBox();
        txtIpartno.ID = "txtIpartno" + tblImportCounter.ToString();
        txtIpartno.Width = Unit.Percentage(99);
        txtIpartno.CssClass = "labelText";
        txtIpartno.ToolTip = "Part No";
        txtIpartno.TabIndex = 1;
        txtIpartno.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtIpartno.Style["background-color"] = "#C8D0D4";
        HiddenField hidIpartno = new HiddenField();
        hidIpartno.ID = "hidIpartno" + tblImportCounter.ToString();
        htmlcell1.Controls.Add(txtIpartno);
        htmlcell1.Controls.Add(hidIpartno);
        #endregion
        #region
        HtmlTableCell htmlcell2 = new HtmlTableCell();
        TextBox txtIdesc = new TextBox();
        txtIdesc.ID = "txtIdesc" + tblImportCounter.ToString();
        txtIdesc.Width = Unit.Percentage(99);
        txtIdesc.CssClass = "labelText";
        txtIdesc.TabIndex = 2;
        txtIdesc.ToolTip = "Description";
        txtIdesc.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtIdesc.Style["background-color"] = "#C8D0D4";
        HiddenField hidIdesc = new HiddenField();
        hidIdesc.ID = "hidIdesc" + tblImportCounter.ToString();
        htmlcell2.Controls.Add(txtIdesc);
        htmlcell2.Controls.Add(hidIdesc);
        #endregion
        #region COO
        HtmlTableCell htmlcell3 = new HtmlTableCell();
        //TextBox txtIcoo = new TextBox();
        //txtIcoo.ID = "txtIcoo" + tblImportCounter.ToString();
        //txtIcoo.Width = Unit.Percentage(99);
        //txtIcoo.CssClass = "labelText";
        //txtIcoo.ToolTip = "";

        DropDownList ddlIcoo = new DropDownList();
        ddlIcoo.ID = "ddlIcoo" + tblImportCounter.ToString();
        ddlIcoo.Width = Unit.Percentage(99);
        ddlIcoo.ToolTip = "COO";
        ddlIcoo.AutoPostBack = true;
        ddlIcoo.TabIndex = 3;
        HiddenField hidIcoo = new HiddenField();
        hidIcoo.ID = "hidIcoo" + tblImportCounter.ToString();
        htmlcell3.Controls.Add(ddlIcoo);
        htmlcell3.Controls.Add(hidIcoo);
        #endregion
        #region//International Unit Price.
        HtmlTableCell htmlcell4 = new HtmlTableCell();
        TextBox txtIUnitPrice = new TextBox();
        txtIUnitPrice.ID = "txtIUnitPrice" + tblImportCounter.ToString();
        txtIUnitPrice.Width = Unit.Percentage(99);
        txtIUnitPrice.CssClass = "labelText";
        txtIUnitPrice.Style["text-align"] = "Right";
        txtIUnitPrice.ToolTip = "";
        txtIUnitPrice.TabIndex = 4;
        txtIUnitPrice.Attributes.Add("onKeyPress", "return isNumberKey(this.id,event)");
        txtIUnitPrice.Attributes.Add("onblur", "return UnitPrice();");
        HiddenField hidIUnitPrice = new HiddenField();
        hidIUnitPrice.ID = "hidIUnitPrice" + tblImportCounter.ToString();
        HiddenField hidUOMID = new HiddenField();
        hidUOMID.ID = "hidUOMID" + tblImportCounter.ToString();
        HiddenField hidRateInc = new HiddenField();
        hidRateInc.ID = "hidRateInc" + tblImportCounter.ToString();
        htmlcell4.Controls.Add(txtIUnitPrice);
        htmlcell4.Controls.Add(hidIUnitPrice);
        htmlcell4.Controls.Add(hidUOMID);
        htmlcell4.Controls.Add(hidRateInc);
        #endregion
        #region//Quantity
        HtmlTableCell htmlcell5 = new HtmlTableCell();
        TextBox txtIQty = new TextBox();
        txtIQty.ID = "txtIQty" + tblImportCounter.ToString();
        txtIQty.Width = Unit.Percentage(99);
        txtIQty.CssClass = "labelText";
        txtIQty.ToolTip = "";
        txtIQty.Style["text-align"] = "Right";
        txtIQty.Attributes.Add("onKeyPress", "return isNumber(event)");
        txtIQty.TabIndex = 5;
        txtIQty.Attributes.Add("onblur", "return InvoiceValue(" + tblImportCounter + ");");
        HiddenField hidIQty = new HiddenField();
        hidIQty.ID = "hidIQty" + tblImportCounter.ToString();
        HiddenField hidInternationalQty = new HiddenField();
        hidInternationalQty.ID = "hidInternationalQty" + tblImportCounter.ToString();
        HiddenField issueqty = new HiddenField();
        issueqty.ID = "issueqty" + tblImportCounter.ToString();
        htmlcell5.Controls.Add(txtIQty);
        htmlcell5.Controls.Add(hidIQty);
        htmlcell5.Controls.Add(hidInternationalQty);
        htmlcell5.Controls.Add(issueqty);
        #endregion
        #region//Extended Value.
        HtmlTableCell htmlcell6 = new HtmlTableCell();
        TextBox txtIExtendVal = new TextBox();
        txtIExtendVal.ID = "txtIExtendVal" + tblImportCounter.ToString();
        txtIExtendVal.Width = Unit.Percentage(99);
        txtIExtendVal.CssClass = "labelText";
        txtIExtendVal.ToolTip = "";
        txtIExtendVal.Style["text-align"] = "Right";
        txtIExtendVal.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtIExtendVal.TabIndex = 6;
        txtIExtendVal.Style["background-color"] = "#C8D0D4";
        HiddenField hidIExtendval = new HiddenField();
        hidIExtendval.ID = "hidIExtendval" + tblImportCounter.ToString();
        htmlcell6.Controls.Add(txtIExtendVal);
        htmlcell6.Controls.Add(hidIExtendval);
        #endregion
        #region//Domestic Unit Price(INR)
        HtmlTableCell htmlcell7 = new HtmlTableCell();
        TextBox txtIUnitPriceINR = new TextBox();
        txtIUnitPriceINR.ID = "txtIUnitPriceINR" + tblImportCounter.ToString();
        txtIUnitPriceINR.Width = Unit.Percentage(99);
        txtIUnitPriceINR.CssClass = "labelText";
        txtIUnitPriceINR.ToolTip = "";
        txtIUnitPriceINR.Style["text-align"] = "Right";
        txtIUnitPriceINR.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtIUnitPriceINR.TabIndex = 7;
        txtIUnitPriceINR.Style["background-color"] = "#C8D0D4";
        HiddenField hidIUnitPriceINR = new HiddenField();
        hidIUnitPriceINR.ID = "hidIUnitPriceINR" + tblImportCounter.ToString();
        htmlcell7.Controls.Add(txtIUnitPriceINR);
        htmlcell7.Controls.Add(hidIUnitPriceINR);
        #endregion
        #region//Invoice Value (INR)
        HtmlTableCell htmlcell8 = new HtmlTableCell();
        TextBox txtIInvoiceVal = new TextBox();
        txtIInvoiceVal.ID = "txtIInvoiceVal" + tblImportCounter.ToString();
        txtIInvoiceVal.Width = Unit.Percentage(99);
        txtIInvoiceVal.CssClass = "labelText";
        txtIInvoiceVal.ToolTip = "";
        txtIInvoiceVal.Style["text-align"] = "Right";
        txtIInvoiceVal.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtIInvoiceVal.Style["background-color"] = "#C8D0D4";
        txtIInvoiceVal.TabIndex = 8;
        HiddenField hidIInvoiceVal = new HiddenField();
        hidIInvoiceVal.ID = "hidIInvoiceVal" + tblImportCounter.ToString();
        htmlcell8.Controls.Add(txtIInvoiceVal);
        htmlcell8.Controls.Add(hidIInvoiceVal);
        #endregion
        #region//Asse Value.
        HtmlTableCell htmlcell9 = new HtmlTableCell();
        TextBox txtIAsseval = new TextBox();
        txtIAsseval.ID = "txtIAsseval" + tblImportCounter.ToString();
        txtIAsseval.Width = Unit.Percentage(99);
        txtIAsseval.CssClass = "labelText";
        txtIAsseval.ToolTip = "";
        txtIAsseval.Text = "0.00";
        txtIAsseval.TabIndex = 9;
        txtIAsseval.Style["text-align"] = "Right";
        txtIAsseval.Attributes.Add("onfocus", "if(this.value=='0.00') this.value='';");
        txtIAsseval.Attributes.Add("onKeyPress", "return isNumberKey(this.id,event)");
        txtIAsseval.Attributes.Add("onblur", "return CustomeDuty(" + tblImportCounter + ");");
        HiddenField hidIAsseval = new HiddenField();
        hidIAsseval.ID = "hidIAsseval" + tblImportCounter.ToString();
        htmlcell9.Controls.Add(txtIAsseval);
        htmlcell9.Controls.Add(hidIAsseval);
        #endregion
        #region//Basic Custome Duty.
        HtmlTableCell htmlcell10 = new HtmlTableCell();
        TextBox txtIBasicCust = new TextBox();
        txtIBasicCust.ID = "txtIBasicCust" + tblImportCounter.ToString();
        txtIBasicCust.Width = Unit.Percentage(40);
        txtIBasicCust.CssClass = "labelText";
        txtIBasicCust.ToolTip = "";
        txtIBasicCust.Text = "0.00";
        txtIBasicCust.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtIBasicCust.Style["background-color"] = "#C8D0D4";
        txtIBasicCust.Style["margin-left"] = "2px";
        txtIBasicCust.Style["text-align"] = "Right";
        txtIBasicCust.TabIndex = 10;
        DropDownList ddlIBasicCust = new DropDownList();
        ddlIBasicCust.ID = "ddlIBasicCust" + tblImportCounter.ToString();
        ddlIBasicCust.Width = Unit.Percentage(50);
        ddlIBasicCust.TabIndex = 11;
        ddlIBasicCust.ToolTip = "Basic Custom Duty";
        //ddlIBasicCust.AutoPostBack = true;
        //ddlIBasicCust.CssClass = "labelText";        
        //ddlIBasicCust.SelectedIndexChanged += new EventHandler(ddlIBasicCust_SelectedIndexChanged);
        ddlIBasicCust.Attributes.Add("onchange", "SetDefaultforBasicCD(this.value," + tblImportCounter + ");");

        HiddenField hidIBasicCust = new HiddenField();
        hidIBasicCust.ID = "hidIBasicCust" + tblImportCounter.ToString();
        hidIBasicCust.Value = "0";
        htmlcell10.Controls.Add(ddlIBasicCust);
        htmlcell10.Controls.Add(hidIBasicCust);
        htmlcell10.Controls.Add(txtIBasicCust);
        #endregion
        #region//CVD
        HtmlTableCell htmlcell11 = new HtmlTableCell();
        TextBox txtICVD = new TextBox();
        txtICVD.ID = "txtICVD" + tblImportCounter.ToString();
        txtICVD.Width = Unit.Percentage(40);
        txtICVD.CssClass = "labelText";
        txtICVD.ToolTip = "";
        txtICVD.Text = "0.00";
        txtICVD.TabIndex = 12;
        txtICVD.Style["margin-left"] = "2px";
        txtICVD.Style["text-align"] = "Right";
        txtICVD.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtICVD.Style["background-color"] = "#C8D0D4";
        DropDownList ddlICVD = new DropDownList();
        ddlICVD.ID = "ddlICVD" + tblImportCounter.ToString();
        ddlICVD.Width = Unit.Percentage(50);
        ddlICVD.ToolTip = "Basic Custom Duty";
        //ddlICVD.AutoPostBack = true;
        ddlICVD.TabIndex = 13;
        //ddlICVD.SelectedIndexChanged += new EventHandler(ddlICVD_SelectedIndexChanged);
        ddlICVD.Attributes.Add("onchange", "SetDefaultforCVD(this.value," + tblImportCounter + ");");
        HiddenField hidICVD = new HiddenField();
        hidICVD.ID = "hidICVD" + tblImportCounter.ToString();
        hidICVD.Value = "0";
        htmlcell11.Controls.Add(ddlICVD);
        htmlcell11.Controls.Add(txtICVD);
        htmlcell11.Controls.Add(hidICVD);
        #endregion
        #region//Educational cess on CVD 2%
        HtmlTableCell htmlcell12 = new HtmlTableCell();
        TextBox txtIEducess = new TextBox();
        txtIEducess.ID = "txtIEducess" + tblImportCounter.ToString();
        txtIEducess.Width = Unit.Percentage(40);
        txtIEducess.CssClass = "labelText";
        txtIEducess.ToolTip = "";
        txtIEducess.Text = "0.00";
        txtIEducess.Style["margin-left"] = "2px";
        txtIEducess.Style["text-align"] = "Right";
        txtIEducess.TabIndex = 14;
        txtIEducess.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtIEducess.Style["background-color"] = "#C8D0D4";
        DropDownList ddleducessoncvd = new DropDownList();
        ddleducessoncvd.ID = "ddleducessoncvd" + tblImportCounter.ToString();
        ddleducessoncvd.Width = Unit.Percentage(50);
        ddleducessoncvd.ToolTip = "Educational Cess On CVD 2%";
        ddleducessoncvd.TabIndex = 15;
        //ddleducessoncvd.AutoPostBack = true;
        ddleducessoncvd.Attributes.Add("onchange", "ForEduCessOnCVD2(this.value," + tblImportCounter + ");");
        //ddleducessoncvd.SelectedIndexChanged +=new EventHandler(ddleducessoncvd_SelectedIndexChanged);
        HiddenField hidIEducess = new HiddenField();
        hidIEducess.ID = "hidIEducess" + tblImportCounter.ToString();

        htmlcell12.Controls.Add(ddleducessoncvd);
        htmlcell12.Controls.Add(txtIEducess);
        htmlcell12.Controls.Add(hidIEducess);
        #endregion
        #region//HEdu cess on CVD 1%
        HtmlTableCell htmlcell13 = new HtmlTableCell();
        TextBox txtIHEducess = new TextBox();
        txtIHEducess.ID = "txtIHEducess" + tblImportCounter.ToString();
        txtIHEducess.Width = Unit.Percentage(40);
        txtIHEducess.CssClass = "labelText";
        txtIHEducess.Style["margin-left"] = "2px";
        txtIHEducess.ToolTip = "";
        txtIHEducess.Text = "0.00";
        txtIHEducess.TabIndex = 16;
        txtIHEducess.Style["text-align"] = "Right";
        txtIHEducess.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtIHEducess.Style["background-color"] = "#C8D0D4";
        DropDownList ddlHeducessoncvd = new DropDownList();
        ddlHeducessoncvd.ID = "ddlHeducessoncvd" + tblImportCounter.ToString();
        ddlHeducessoncvd.Width = Unit.Percentage(50);
        ddlHeducessoncvd.ToolTip = "Educational Cess On CVD 1%";
        //ddlHeducessoncvd.AutoPostBack = true;
        ddlHeducessoncvd.TabIndex = 17;
        ddlHeducessoncvd.Attributes.Add("onchange", "ForEduCessOnCVD1(this.value," + tblImportCounter + ");");
        //ddlHeducessoncvd.SelectedIndexChanged +=new EventHandler(ddlHeducessoncvd_SelectedIndexChanged);
        HiddenField hidIHeducess = new HiddenField();
        hidIHeducess.ID = "hidIHeducess" + tblImportCounter.ToString();
        htmlcell13.Controls.Add(ddlHeducessoncvd);
        htmlcell13.Controls.Add(txtIHEducess);
        htmlcell13.Controls.Add(hidIHeducess);
        #endregion
        #region//Total Duty.
        HtmlTableCell htmlcell14 = new HtmlTableCell();
        TextBox txtITotalduty = new TextBox();
        txtITotalduty.ID = "txtITotalduty" + tblImportCounter.ToString();
        txtITotalduty.Width = Unit.Percentage(99);
        txtITotalduty.CssClass = "labelText";
        txtITotalduty.ToolTip = "";
        txtITotalduty.Text = "0.00";
        txtITotalduty.TabIndex = 18;
        txtITotalduty.Style["text-align"] = "Right";
        txtITotalduty.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtITotalduty.Style["background-color"] = "#C8D0D4";
        HiddenField hidITotalduty = new HiddenField();
        hidITotalduty.ID = "hidITotalduty" + tblImportCounter.ToString();
        htmlcell14.Controls.Add(txtITotalduty);
        htmlcell14.Controls.Add(hidITotalduty);
        #endregion
        #region//Custome Educational Cess 2%.
        HtmlTableCell htmlcell15 = new HtmlTableCell();
        TextBox txtICustomedu = new TextBox();
        txtICustomedu.ID = "txtICustomedu" + tblImportCounter.ToString();
        txtICustomedu.Width = Unit.Percentage(40);
        txtICustomedu.CssClass = "labelText";
        txtICustomedu.ToolTip = "";
        txtICustomedu.Text = "0.00";
        txtICustomedu.TabIndex = 19;
        txtICustomedu.Style["text-align"] = "Right";
        txtICustomedu.Style["margin-left"] = "2px";
        txtICustomedu.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtICustomedu.Style["background-color"] = "#C8D0D4";
        DropDownList ddleducessoncustom = new DropDownList();
        ddleducessoncustom.ID = "ddleducessoncustom" + tblImportCounter.ToString();
        ddleducessoncustom.Width = Unit.Percentage(50);
        ddleducessoncustom.ToolTip = "";
        ddleducessoncustom.TabIndex = 20;
        //ddleducessoncustom.AutoPostBack = true;
        ddleducessoncustom.Items.Insert(0, new ListItem("None", "0"));
        ddleducessoncustom.Items.Insert(1, new ListItem("2%", "2"));
        ddleducessoncustom.Attributes.Add("onchange", "SetDefaultforeducessoncustom(this.value," + tblImportCounter + ");");
        //ddleducessoncustom.SelectedIndexChanged +=new EventHandler(ddleducessoncustom_SelectedIndexChanged);
        HiddenField hidICustomedu = new HiddenField();
        hidICustomedu.ID = "hidICustomedu" + tblImportCounter.ToString();
        htmlcell15.Controls.Add(ddleducessoncustom);
        htmlcell15.Controls.Add(txtICustomedu);
        htmlcell15.Controls.Add(hidICustomedu);
        #endregion
        #region//Custome H & S Educational Cess 1%.
        HtmlTableCell htmlcell16 = new HtmlTableCell();
        TextBox txtICustomHSedu = new TextBox();
        txtICustomHSedu.ID = "txtICustomHSedu" + tblImportCounter.ToString();
        txtICustomHSedu.Width = Unit.Percentage(40);
        txtICustomHSedu.CssClass = "labelText";
        txtICustomHSedu.ToolTip = "";
        txtICustomHSedu.Text = "0.00";
        txtICustomHSedu.TabIndex = 21;
        txtICustomHSedu.Style["margin-left"] = "2px";
        txtICustomHSedu.Style["text-align"] = "Right";
        txtICustomHSedu.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtICustomHSedu.Style["background-color"] = "#C8D0D4";
        DropDownList ddlHSeducessoncustom = new DropDownList();
        ddlHSeducessoncustom.ID = "ddlHSeducessoncustom" + tblImportCounter.ToString();
        ddlHSeducessoncustom.Width = Unit.Percentage(50);
        ddlHSeducessoncustom.ToolTip = "";
        ddlHSeducessoncustom.TabIndex = 22;
        //ddlHSeducessoncustom.AutoPostBack = true;
        ddlHSeducessoncustom.Items.Insert(0, new ListItem("None", "0"));
        ddlHSeducessoncustom.Items.Insert(1, new ListItem("1%", "1"));
        ddlHSeducessoncustom.Attributes.Add("onchange", "SetDefaultforHSeducessoncustom(this.value," + tblImportCounter + ");");
        //ddlHSeducessoncustom.SelectedIndexChanged +=new EventHandler(ddlHSeducessoncustom_SelectedIndexChanged);
        HiddenField hidICustomHSedu = new HiddenField();
        hidICustomHSedu.ID = "hidICustomHSedu" + tblImportCounter.ToString();
        htmlcell16.Controls.Add(ddlHSeducessoncustom);
        htmlcell16.Controls.Add(txtICustomHSedu);
        htmlcell16.Controls.Add(hidICustomHSedu);
        #endregion
        #region//Additional Duty.
        HtmlTableCell htmlcell17 = new HtmlTableCell();
        TextBox txtIAddDuty = new TextBox();
        txtIAddDuty.ID = "txtIAddDuty" + tblImportCounter.ToString();
        txtIAddDuty.Width = Unit.Percentage(40);
        txtIAddDuty.CssClass = "labelText";
        txtIAddDuty.ToolTip = "";
        txtIAddDuty.Text = "0.00";
        txtIAddDuty.TabIndex = 23;
        txtIAddDuty.Style["text-align"] = "Right";
        txtIAddDuty.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtIAddDuty.Style["background-color"] = "#C8D0D4";
        txtIAddDuty.Style["margin-left"] = "2px";
        DropDownList ddlIAddDuty = new DropDownList();
        ddlIAddDuty.ID = "ddlIAddDuty" + tblImportCounter.ToString();
        ddlIAddDuty.Width = Unit.Percentage(50);
        ddlIAddDuty.ToolTip = "";
        ddlIAddDuty.TabIndex = 24;
        //ddlIAddDuty.AutoPostBack = true;
        //ddlIAddDuty.SelectedIndexChanged += new EventHandler(ddlIAddDuty_SelectedIndexChanged);
        ddlIAddDuty.Attributes.Add("onchange", "SetDefaultforADDduty(this.value," + tblImportCounter + ");");
        HiddenField hidIAddDuty = new HiddenField();
        hidIAddDuty.ID = "hidIAddDuty" + tblImportCounter.ToString();
        hidIAddDuty.Value = "0";
        htmlcell17.Controls.Add(ddlIAddDuty);
        htmlcell17.Controls.Add(txtIAddDuty);
        htmlcell17.Controls.Add(hidIAddDuty);
        #endregion
        #region//grand total.
        HtmlTableCell htmlcell18 = new HtmlTableCell();
        TextBox txtIGrandTotal = new TextBox();
        txtIGrandTotal.ID = "txtIGrandTotal" + tblImportCounter.ToString();
        txtIGrandTotal.Width = Unit.Percentage(99);
        txtIGrandTotal.CssClass = "labelText";
        txtIGrandTotal.ToolTip = "";
        txtIGrandTotal.Text = "0.00";
        txtIGrandTotal.TabIndex = 25;
        txtIGrandTotal.Style["text-align"] = "Right";
        txtIGrandTotal.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtIGrandTotal.Style["background-color"] = "#C8D0D4";
        HiddenField hidIGrandTotal = new HiddenField();
        hidIGrandTotal.ID = "hidIGrandTotal" + tblImportCounter.ToString();
        htmlcell18.Controls.Add(txtIGrandTotal);
        htmlcell18.Controls.Add(hidIGrandTotal);
        #endregion
        #region Clear/Freight
        HtmlTableCell htmlcell19 = new HtmlTableCell();
        TextBox txtIClearFreight = new TextBox();
        txtIClearFreight.ID = "txtIClearFreight" + tblImportCounter.ToString();
        txtIClearFreight.Width = Unit.Percentage(99);
        txtIClearFreight.CssClass = "labelText";
        txtIClearFreight.ToolTip = "";
        txtIClearFreight.Text = "0.00";
        txtIClearFreight.TabIndex = 26;
        txtIClearFreight.Style["text-align"] = "Right";
        txtIClearFreight.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtIClearFreight.Style["background-color"] = "#C8D0D4";
        HiddenField hidIClearFreight = new HiddenField();
        hidIClearFreight.ID = "hidIClearFreight" + tblImportCounter.ToString();
        htmlcell19.Controls.Add(txtIClearFreight);
        htmlcell19.Controls.Add(hidIClearFreight);
        #endregion
        #region landedCost
        HtmlTableCell htmlcell20 = new HtmlTableCell();
        TextBox txtILandedCost = new TextBox();
        txtILandedCost.ID = "txtILandedCost" + tblImportCounter.ToString();
        txtILandedCost.Width = Unit.Percentage(99);
        txtILandedCost.CssClass = "labelText";
        txtILandedCost.ToolTip = "";
        txtILandedCost.Text = "0.00";
        txtILandedCost.TabIndex = 27;
        txtILandedCost.Style["text-align"] = "Right";
        txtILandedCost.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtILandedCost.Style["background-color"] = "#C8D0D4";
        HiddenField hidILandedCost = new HiddenField();
        hidILandedCost.ID = "hidILandedCost" + tblImportCounter.ToString();
        htmlcell20.Controls.Add(txtILandedCost);
        htmlcell20.Controls.Add(hidILandedCost);
        #endregion
        #region InventCost
        HtmlTableCell htmlcell21 = new HtmlTableCell();
        htmlcell21.Style["display"] = "none";
        TextBox txtIInventCost = new TextBox();
        txtIInventCost.ID = "txtIInventCost" + tblImportCounter.ToString();
        txtIInventCost.Width = Unit.Percentage(99);
        txtIInventCost.CssClass = "labelText";
        txtIInventCost.ToolTip = "";
        txtIInventCost.Text = "0.00";
        txtIInventCost.TabIndex = 28;
        txtIInventCost.Style["text-align"] = "Right";
        txtIInventCost.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtIInventCost.Style["background-color"] = "#C8D0D4";
        HiddenField hidIInventCost = new HiddenField();
        hidIInventCost.ID = "hidIInventCost" + tblImportCounter.ToString();
        htmlcell21.Controls.Add(txtIInventCost);
        htmlcell21.Controls.Add(hidIInventCost);
        #endregion

        htmlrow.Cells.Add(htmlcell1);
        htmlrow.Cells.Add(htmlcell2);
        htmlrow.Cells.Add(htmlcell3);
        htmlrow.Cells.Add(htmlcell4);
        htmlrow.Cells.Add(htmlcell5);
        htmlrow.Cells.Add(htmlcell6);
        htmlrow.Cells.Add(htmlcell7);
        htmlrow.Cells.Add(htmlcell8);
        htmlrow.Cells.Add(htmlcell9);
        htmlrow.Cells.Add(htmlcell10);
        htmlrow.Cells.Add(htmlcell11);
        htmlrow.Cells.Add(htmlcell12);
        htmlrow.Cells.Add(htmlcell13);
        htmlrow.Cells.Add(htmlcell14);
        htmlrow.Cells.Add(htmlcell15);
        htmlrow.Cells.Add(htmlcell16);
        htmlrow.Cells.Add(htmlcell17);
        htmlrow.Cells.Add(htmlcell18);
        htmlrow.Cells.Add(htmlcell19);
        htmlrow.Cells.Add(htmlcell20);
        htmlrow.Cells.Add(htmlcell21);

        tblImportItemLevel.Rows.Add(htmlrow);
        hidimportTblItems.Value = tblImportCounter.ToString();
    }
    //Education Cess on Custom 2%
    protected void GenerateFolioNo()
    {
        DataTable DtFolioNo = DU.getdata("Select FolioNo from IVR_TRAN_MAIN");
    }
    protected void ddleducessoncustom_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        int rowIndex = Convert.ToInt32(ddl.ID.ToString().Substring(18));
        TextBox txtTotalDuty = (TextBox)tblImportItemLevel.Rows[rowIndex].FindControl("txtITotalduty" + rowIndex.ToString());
        TextBox txtCustomEdu = (TextBox)tblImportItemLevel.Rows[rowIndex].FindControl("txtICustomedu" + rowIndex.ToString());
        if (ddl.SelectedValue != "0")
        {
            txtCustomEdu.Text = (Convert.ToDecimal(txtTotalDuty.Text) * Convert.ToDecimal(ddl.SelectedValue) / 100).ToString("N2");
        }
        else
        {
            txtCustomEdu.Text = (Convert.ToDecimal(txtTotalDuty.Text) * Convert.ToDecimal(ddl.SelectedValue) / 100).ToString("N2");
        }
        CustomEduCess();
    }
    //Higher Education Cess on Custom 1%
    protected void ddlHSeducessoncustom_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        int rowIndex = Convert.ToInt32(ddl.ID.ToString().Substring(20));
        TextBox txtTotalDuty = (TextBox)tblImportItemLevel.Rows[rowIndex].FindControl("txtITotalduty" + rowIndex.ToString());
        TextBox txtCustomHEdu = (TextBox)tblImportItemLevel.Rows[rowIndex].FindControl("txtICustomHSedu" + rowIndex.ToString());
        if (ddl.SelectedValue != "0")
        {
            txtCustomHEdu.Text = (Convert.ToDecimal(txtTotalDuty.Text) * Convert.ToDecimal(ddl.SelectedValue) / 100).ToString("N2");
        }
        else
        {
            txtCustomHEdu.Text = (Convert.ToDecimal(txtTotalDuty.Text) * Convert.ToDecimal(ddl.SelectedValue) / 100).ToString("N2");
        }
        SHCustomEduCess();
    }
    private void CVD()
    {
        int count = tblImportItemLevel.Rows.Count;
        double a = 0.00;
        for (int j = 1; j < count; j++)
        {
            HiddenField HidCVD = (HiddenField)tblImportItemLevel.Rows[j].FindControl("hidICVD" + j);
            if (HidCVD.Value != "")
            {
                a = a + Convert.ToDouble(HidCVD.Value);
                txtCvd.Text = (a).ToString("N2");
            }
        }
    }
    private void ECessOnCVD()
    {
        int count = tblImportItemLevel.Rows.Count;
        double a = 0.00;
        for (int j = 1; j < count; j++)
        {
            TextBox txtEduCVD = (TextBox)tblImportItemLevel.Rows[j].FindControl("txtIEducess" + j);
            if (txtEduCVD.Text != "")
            {
                a = a + Convert.ToDouble(txtEduCVD.Text);
                txtEcessonCVD.Text = (a).ToString("N2");
            }
        }
    }
    private void SHECessOnCVD()
    {
        int count = tblImportItemLevel.Rows.Count;
        double a = 0.00;
        for (int j = 1; j < count; j++)
        {
            TextBox txtHEduCVD = (TextBox)tblImportItemLevel.Rows[j].FindControl("txtIHEducess" + j);
            if (txtHEduCVD.Text != "")
            {
                a = a + Convert.ToDouble(txtHEduCVD.Text);
                txtSHECessOnCVD.Text = (a).ToString("N2");
            }
        }
    }
    private void CustomEduCess()
    {
        int count = tblImportItemLevel.Rows.Count;
        double a = 0.00;
        for (int j = 1; j < count; j++)
        {
            TextBox txtCustomEdu = (TextBox)tblImportItemLevel.Rows[j].FindControl("txtICustomedu" + j);
            if (txtCustomEdu.Text != "")
            {
                a = a + Convert.ToDouble(txtCustomEdu.Text);
                txtCustomeduCess.Text = (a).ToString("N2");
            }
        }
    }
    private void SHCustomEduCess()
    {
        int count = tblImportItemLevel.Rows.Count;
        double a = 0.00;
        for (int j = 1; j < count; j++)
        {
            TextBox txtCustomHEdu = (TextBox)tblImportItemLevel.Rows[j].FindControl("txtICustomHSedu" + j);
            if (txtCustomHEdu.Text != "")
            {
                a = a + Convert.ToDouble(txtCustomHEdu.Text);
                txtSHCustomEduCess.Text = (a).ToString("N2");
            }
        }
    }
    private void AdditionalDuty()
    {
        int count = tblImportItemLevel.Rows.Count;
        double a = 0.00;
        for (int j = 1; j < count; j++)
        {
            HiddenField hidIAddDuty = (HiddenField)tblImportItemLevel.Rows[j].FindControl("hidIAddDuty" + j);
            if (hidIAddDuty.Value != "")
            {
                a = a + Convert.ToDouble(hidIAddDuty.Value);
                txtAddlDuty.Text = (a).ToString("N2");
            }
        }
    }
    private void DutyPayable()
    {
        int count = tblImportItemLevel.Rows.Count;
        double a = 0.00;
        for (int j = 1; j < count; j++)
        {
            TextBox txtIGrandTotal = (TextBox)tblImportItemLevel.Rows[j].FindControl("txtIGrandTotal" + j);
            if (txtIGrandTotal.Text != "")
            {
                a = a + Convert.ToDouble(txtIGrandTotal.Text);
                txtDutyPayable.Text = (a).ToString("N2");
            }
        }
    }    //

    protected void AddMoreTblItemLevel()
    {
        tblItemsCounter++;
        HtmlTableRow HTTblItemRow = new HtmlTableRow();

        HtmlTableCell HTTblItemCell1 = new HtmlTableCell();
        Label lblItemName = new Label();
        lblItemName.ID = "lblItemName" + tblItemsCounter.ToString();
        lblItemName.Width = Unit.Percentage(99);
        lblItemName.CssClass = "labelText";
        //lblItemName.BackColor = Color.FromName("#EAF2F2");
        lblItemName.ToolTip = "Not Changable";
        HiddenField hidItemId = new HiddenField();
        hidItemId.ID = "hidItemId" + tblItemsCounter.ToString();
        HTTblItemCell1.Controls.Add(lblItemName);
        HTTblItemCell1.Controls.Add(hidItemId);

        HtmlTableCell HTTblItemCell2 = new HtmlTableCell();
        Label lblUnitName = new Label();
        lblUnitName.ID = "lblUnitName" + tblItemsCounter.ToString();
        lblUnitName.Width = Unit.Percentage(99);
        lblUnitName.CssClass = "labelText";
        lblUnitName.BackColor = Color.FromName("#EAF2F2");
        HiddenField hidUnitId = new HiddenField();
        hidUnitId.ID = "hidUnitId" + tblItemsCounter.ToString();
        HTTblItemCell2.Controls.Add(lblUnitName);
        HTTblItemCell2.Controls.Add(hidUnitId);

        HtmlTableCell HTTblItemCell3 = new HtmlTableCell();
        TextBox txtReceivedQty = new TextBox();
        txtReceivedQty.ID = "txtReceivedQty" + tblItemsCounter.ToString();
        txtReceivedQty.Width = Unit.Percentage(99);
        txtReceivedQty.CssClass = "inputnumber";
        txtReceivedQty.Text = "0.00";
        txtReceivedQty.BackColor = Color.FromName("#EAF2F2");
        txtReceivedQty.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtReceivedQty.Attributes.Add("onpaste", "return false");
        txtReceivedQty.Attributes.Add("oncut", "return false");
        txtReceivedQty.AutoCompleteType = AutoCompleteType.Disabled;
        HiddenField hidOrderQty = new HiddenField();
        hidOrderQty.ID = "hidOrderQty" + tblItemsCounter.ToString();
        HTTblItemCell3.Controls.Add(txtReceivedQty);
        HTTblItemCell3.Controls.Add(hidOrderQty);

        HtmlTableCell HTTblItemCell4 = new HtmlTableCell();
        Button btnQuantity = new Button();
        btnQuantity.ID = "btnQuantity" + tblItemsCounter.ToString();
        btnQuantity.Text = "...";
        btnQuantity.CssClass = "button";
        btnQuantity.Width = Unit.Percentage(99);
        HiddenField hidLocationId = new HiddenField();
        hidLocationId.ID = "hidLocationId" + tblItemsCounter.ToString();
        HTTblItemCell4.Controls.Add(btnQuantity);
        HTTblItemCell4.Controls.Add(hidLocationId);

        HtmlTableCell HTTblItemCell5 = new HtmlTableCell();
        TextBox txtRate = new TextBox();
        txtRate.ID = "txtRate" + tblItemsCounter.ToString();
        txtRate.Width = Unit.Percentage(99);
        txtRate.CssClass = "inputnumber";
        txtRate.Text = "0.00";
        txtRate.Attributes.Add("onfocus", "return RemoveZero(this.id);");
        txtRate.Attributes.Add("onKeyPress", "return isNumberKey(this.id,event)");
        txtRate.Attributes.Add("onblur", "return CalculateAmount();");
        txtRate.AutoCompleteType = AutoCompleteType.Disabled;
        HiddenField hidPoRate = new HiddenField();
        hidPoRate.ID = "hidPoRate" + tblItemsCounter.ToString();
        HTTblItemCell5.Controls.Add(txtRate);
        HTTblItemCell5.Controls.Add(hidPoRate);

        HtmlTableCell HTTblItemCell6 = new HtmlTableCell();
        TextBox txtGrossAmt = new TextBox();
        txtGrossAmt.ID = "txtGrossAmt" + tblItemsCounter.ToString();
        txtGrossAmt.Width = Unit.Percentage(99);
        txtGrossAmt.CssClass = "inputnumber";
        txtGrossAmt.BackColor = Color.FromName("#EAF2F2");
        txtGrossAmt.ToolTip = "Gross Amount";
        txtGrossAmt.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtGrossAmt.Attributes.Add("onpaste", "return false");
        txtGrossAmt.Attributes.Add("oncut", "return false");
        txtGrossAmt.AutoCompleteType = AutoCompleteType.Disabled;
        HTTblItemCell6.Controls.Add(txtGrossAmt);

        HtmlTableCell HTTblItemCell7 = new HtmlTableCell();
        DropDownList ddlTaxType = new DropDownList();
        ddlTaxType.ID = "ddlTaxType" + tblItemsCounter.ToString();
        ddlTaxType.Width = Unit.Percentage(99);
        ddlTaxType.CssClass = "dropdown";
        BindTaxSubGroup(ddlTaxType);
        ddlTaxType.AutoPostBack = true;
        ddlTaxType.Attributes.Add("onclick", "return checkTaxGroup(this.id)");
        ddlTaxType.SelectedIndexChanged += new EventHandler(ddlTaxType_SelectedIndexChanged);
        HiddenField hidTaxRate = new HiddenField();
        hidTaxRate.ID = "hidTaxRate" + tblItemsCounter.ToString();
        HTTblItemCell7.Controls.Add(ddlTaxType);
        HTTblItemCell7.Controls.Add(hidTaxRate);

        HtmlTableCell HTTblItemCell8 = new HtmlTableCell();
        TextBox txtTaxAmt = new TextBox();
        txtTaxAmt.ID = "txtTaxAmt" + tblItemsCounter.ToString();
        txtTaxAmt.Width = Unit.Percentage(99);
        txtTaxAmt.CssClass = "inputnumber";
        txtTaxAmt.ToolTip = "Tax Amount";
        txtTaxAmt.BackColor = Color.FromName("#EAF2F2");
        txtTaxAmt.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtTaxAmt.Attributes.Add("onpaste", "return false");
        txtTaxAmt.Attributes.Add("oncut", "return false");
        txtTaxAmt.AutoCompleteType = AutoCompleteType.Disabled;
        HTTblItemCell8.Controls.Add(txtTaxAmt);

        HtmlTableCell HTTblItemCell9 = new HtmlTableCell();
        TextBox txtAmountPayable = new TextBox();
        txtAmountPayable.ID = "txtAmountPayable" + tblItemsCounter.ToString();
        txtAmountPayable.Width = Unit.Percentage(99);
        txtAmountPayable.CssClass = "inputnumber";
        txtAmountPayable.BackColor = Color.FromName("#EAF2F2");
        txtAmountPayable.ToolTip = "Net Amount";
        txtAmountPayable.Attributes.Add("onkeydown", "return CatchTab(this.id,event);");
        txtAmountPayable.Attributes.Add("onpaste", "return false");
        txtAmountPayable.Attributes.Add("oncut", "return false");
        txtAmountPayable.AutoCompleteType = AutoCompleteType.Disabled;
        HTTblItemCell9.Controls.Add(txtAmountPayable);

        HtmlTableCell HTTblItemCell10 = new HtmlTableCell();
        DropDownList ddlPurchaseLedger = new DropDownList();
        ddlPurchaseLedger.ID = "ddlPurchaseLedger" + tblItemsCounter.ToString();
        ddlPurchaseLedger.Width = Unit.Percentage(99);
        ddlPurchaseLedger.CssClass = "dropdown";
        BindPurchaseLedger(ddlPurchaseLedger);
        HTTblItemCell10.Controls.Add(ddlPurchaseLedger);

        HtmlTableCell HTTblItemCell11 = new HtmlTableCell();
        DropDownList ddlTaxLedger = new DropDownList();
        ddlTaxLedger.ID = "ddlTaxLedger" + tblItemsCounter.ToString();
        ddlTaxLedger.Width = Unit.Percentage(99);
        ddlTaxLedger.CssClass = "dropdown";
        BindTaxLedger(ddlTaxLedger);
        HTTblItemCell11.Controls.Add(ddlTaxLedger);

        HTTblItemRow.Cells.Add(HTTblItemCell1);
        HTTblItemRow.Cells.Add(HTTblItemCell2);
        HTTblItemRow.Cells.Add(HTTblItemCell3);
        HTTblItemRow.Cells.Add(HTTblItemCell4);
        HTTblItemRow.Cells.Add(HTTblItemCell5);
        HTTblItemRow.Cells.Add(HTTblItemCell6);
        HTTblItemRow.Cells.Add(HTTblItemCell7);
        HTTblItemRow.Cells.Add(HTTblItemCell8);
        HTTblItemRow.Cells.Add(HTTblItemCell9);
        HTTblItemRow.Cells.Add(HTTblItemCell10);
        HTTblItemRow.Cells.Add(HTTblItemCell11);
        tblTaxItemLevel.Rows.Add(HTTblItemRow);
        hidControlTblItems.Value = tblItemsCounter.ToString();
    }
    protected void BindPurchaseOrderDetails()
    {//****************BY Harish
        SqlParameter[] sparam = {
                                    new SqlParameter("@POID",Request.QueryString["Poid"].ToString())
                                };
        DataTable DTPoDetails = DU.getdatausingprocedure("USP_IVR_GetPoDetailsForPurchaseInvoice", sparam);
        if (DTPoDetails.Rows.Count > 0)
        {
            hyperPoNumber.Text = DTPoDetails.Rows[0]["PoVoucherNo"].ToString();
            lblSupplier.Text = DTPoDetails.Rows[0]["LNAME"].ToString();
            hidSupplierID.Value = DTPoDetails.Rows[0]["LID"].ToString();
            ddlTaxGroup.SelectedValue = DTPoDetails.Rows[0]["TAXGROUPID"].ToString();
            ddlleasedtype.SelectedValue = DTPoDetails.Rows[0]["LEASEDTYPE"].ToString();
            ddlcurrency.SelectedValue = DTPoDetails.Rows[0]["currency"].ToString();
            templocationid.Value = DTPoDetails.Rows[0]["DeliveryLocation"].ToString();
            rbtCashCredit.SelectedValue = DTPoDetails.Rows[0]["Cash_Credit"].ToString();
            HidBillFormat.Value = DTPoDetails.Rows[0]["FORMATNAME"].ToString();

            if (ddlcurrency.SelectedIndex > 1)
            {
                lblexchangerate.Visible = true;
                txtexcrate.Visible = true;
            }
        }
        for (int i = 1; i < tblTaxItemLevel.Rows.Count; i++)
        {
            DropDownList ddl = (DropDownList)tblTaxItemLevel.Rows[i].FindControl("ddlsalestax" + i.ToString());
            if (ddlTaxGroup.SelectedIndex > 0)
            {
                strsql = "select SUBCLASSID,SUBCLASSNAME from UVW_ACC_TaxMaster where mainclassid='" + ddlTaxGroup.SelectedValue + "'";
                DataTable DT = DU.getdata(strsql);
                if (DT.Rows.Count > 0)
                {
                    ddl.Items.Clear();
                    ddl.DataSource = DT;
                    ddl.DataTextField = "SUBCLASSNAME";
                    ddl.DataValueField = "SUBCLASSID";
                    ddl.DataBind();
                    ddl.Items.Insert(0, new ListItem("-- Select VAT/CST --", "0"));
                }
            }
        }
        //for Check Tin No
        string strvattin = "select IsNull(lR.VATTIN,'') as TinNo from ACC_LEDREGDETAILS lR inner join ACC_LEDMAST LM on lR.LID=LM.LID where LM.LID=" + hidSupplierID.Value;
        DataTable DTTin = DU.getdata(strvattin);
        if (DTTin.Rows.Count > 0)
        {
            if (DTTin.Rows[0]["TinNo"].ToString() == "")
            {
                hidCheckTinNo.Value = "0";  //0-False,1-True;
            }
        }
    }
    protected void BindPOTaxItemLevel()//For Domestic
    {
        PurchaseReceiveDetails = "";
        SqlParameter[] sparam = {
                                    new SqlParameter("@POID",Request.QueryString["Poid"].ToString())
                                };
        DataTable DTPoDetails = DU.getdatausingprocedure("USP_IVR_GetPoDetailsForPurchaseInvoice", sparam);
        if (DTPoDetails.Rows.Count > 0)
        {
            int rowCount = DTPoDetails.Rows.Count;
            if (rowCount > 0)
            {
                for (int i = 1; i <= rowCount; i++)
                {
                    AddRows();
                }
            }
            //Enter Value in the Generated rows.
            for (int i = 1; i <= rowCount; i++)
            {
                TextBox txtpartno = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtpartno" + i.ToString());
                HiddenField issueqty = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("issueqty" + i.ToString());
                HiddenField hidpartno = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hiPartId" + i.ToString());
                TextBox txtdesc = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtdesc" + i.ToString());
                TextBox txtqty = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtqty" + i.ToString());
                HiddenField hiddenqty = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidqty" + i.ToString());
                HiddenField hiddenDomesticqty = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidDoqty" + i.ToString());
                DropDownList ddlvatcst = (DropDownList)tblTaxItemLevel.Rows[i].FindControl("ddlsalestax" + i.ToString());
                HiddenField hidLocationId = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidLocationId" + i.ToString());
                TextBox txtvatcstamount = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtvatcstamt" + i.ToString());
                HiddenField hidunitprice = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidunitprice" + i.ToString());
                TextBox txtunitprice = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtunitprice" + i.ToString());
                HiddenField hidUOMID = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidUOMID" + i.ToString());
                HiddenField hidRateIncTax = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidRateIncTax" + i.ToString());
                TextBox txtlandedCost = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txttotallanded" + i.ToString());
                TextBox txtSubamount = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtsubamount" + i.ToString());
                DropDownList ddlSalesTax = (DropDownList)tblTaxItemLevel.Rows[i].FindControl("ddlsalestax" + i.ToString());
                TextBox txtInsurance = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtinsurance" + i.ToString());
                TextBox txtServiceTax = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtServiceTax" + i.ToString());
                TextBox txtServiceTaxAmt = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtServiceTaxAmount" + i.ToString());
                TextBox txtfreight = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtfreight" + i.ToString());
                TextBox txtpackaging = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtpackaging" + i.ToString());

                ddlvatcst.Items.Insert(0, new ListItem("--Select VAT/CST--", "0"));
                issueqty.Value = DTPoDetails.Rows[i - 1]["ISSUEQTY"].ToString();
                hiddenqty.Value = DTPoDetails.Rows[i - 1]["OrderQty"].ToString();
                
                txtpartno.Text = DTPoDetails.Rows[i - 1]["ITMCODE"].ToString();
                hidpartno.Value = DTPoDetails.Rows[i - 1]["ItemId"].ToString();
                txtdesc.Text = DTPoDetails.Rows[i - 1]["ITEMNAME"].ToString();
                hidunitprice.Value = DTPoDetails.Rows[i - 1]["PORATE"].ToString();
                hidUOMID.Value = DTPoDetails.Rows[i - 1]["UOMID"].ToString();
                hidRateIncTax.Value = DTPoDetails.Rows[i - 1]["RateInclTax"].ToString();

                if (hidunitprice.Value != "")
                {
                    txtunitprice.Text = Convert.ToDouble(hidunitprice.Value).ToString();
                }
                if (hiddenqty.Value != "")
                {
                    txtqty.Text = Convert.ToDouble(hiddenqty.Value).ToString();
                    hiddenDomesticqty.Value = Convert.ToDouble(hiddenqty.Value).ToString();
                }
                txtunitprice.ToolTip = "Unit Price(" + string.Format("{0:0.00}", Convert.ToDouble(hidunitprice.Value)) + ")"; ;
                txtqty.ToolTip = "Qty(" + string.Format("{0:0.00}", Convert.ToDouble(DTPoDetails.Rows[i - 1]["ITEMQTY"].ToString())) + ") " + "/ Balance Qty(" + string.Format("{0:0.00}", Convert.ToDouble(hiddenqty.Value)) + ")";
                if (!IsPostBack)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Calculation", "Calculate("+i+");", true);
                }
                //For Log of the Item.
                PurchaseReceiveDetails += "PartNO=" + txtpartno.Text + ",Desciption=" + txtdesc.Text + ",UnitPrice=" + txtunitprice.Text + ",Qty=" + txtqty.Text + ",SubAmount=" + txtSubamount.Text + ",SalesTax=" + ddlSalesTax.SelectedItem.Text + ",ServiceTax=" + txtServiceTax.Text + ",ServiceTaxAmount=" + txtServiceTaxAmt.Text + ",Freight=" + txtfreight.Text + ",Packaging=" + txtpackaging.Text + ",Insurance=" + txtInsurance.Text + ",LandedCost=" + txtlandedCost.Text;
            }
        }
    }
    protected void BindTaxSubGroup(DropDownList ddlsalestax)//a common function for bind tax type dropdown list according tax group
    {
        if (ddlTaxGroup.SelectedIndex > 0)
        {
            strsql = "select SUBCLASSID,SUBCLASSNAME from UVW_ACC_TaxMaster where mainclassid='" + ddlTaxGroup.SelectedValue + "'";
            DataTable DT = DU.getdata(strsql);
            if (DT.Rows.Count > 0)
            {
                ddlsalestax.Items.Clear();
                ddlsalestax.DataSource = DT;
                ddlsalestax.DataTextField = "SUBCLASSNAME";
                ddlsalestax.DataValueField = "SUBCLASSID";
                ddlsalestax.DataBind();
                ddlsalestax.Items.Insert(0, new ListItem(" ", "0"));
            }
        }
        else
        {
            ddlsalestax.Items.Clear();
        }
    }
    protected void ddlTaxType_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        string ddlid = ddl.ID.ToString().Substring(10);
        int rowIndex = Convert.ToInt32(ddlid.ToString());
        HiddenField hidTaxRate = (HiddenField)tblTaxItemLevel.Rows[rowIndex].FindControl("hidTaxRate" + rowIndex.ToString());
        if (Convert.ToInt32(ddl.SelectedValue) > 0)
        {
            strsql = "select DEFTAXRATE from UVW_ACC_TaxMaster where mainclassid='" + ddlTaxGroup.SelectedValue + "' and subclassid='" + ddl.SelectedValue + "'";
            DataTable DT = DU.getdata(strsql);
            if (DT.Rows.Count > 0)
            {
                if (DT.Rows[0]["DEFTAXRATE"].ToString() != string.Empty)
                {
                    double TaxRate = Convert.ToDouble(DT.Rows[0]["DEFTAXRATE"].ToString());
                    hidTaxRate.Value = TaxRate.ToString();
                }
                else
                {
                    hidTaxRate.Value = "";
                }
            }
            else
            {
                hidTaxRate.Value = "";
            }
            //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "setdefaultvalue("+ddl.SelectedValue+"); Calculate();", true);
        }
        else
        {
            ddl.SelectedValue = "0";
            hidTaxRate.Value = "";
        }
        //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "return Calculate();", true);
    }
    protected void Bind_VoucherNo()
    {
        string MainVoucher = "";
        string Prepix = "";
        string Suffix = "";
        strsql = "Select tfoid from ivr_tranformat where trantype=4";
        DataTable DTTfoid = DU.getdata(strsql);
        if (DTTfoid.Rows.Count > 0)
        {
            hidBillformatId.Value = DTTfoid.Rows[0]["tfoid"].ToString();
            strsql = "select max(convert(int,TRNNUM)) as PoVoucherNo from IVR_TRAN_MAIN where TFOID='" + DTTfoid.Rows[0]["tfoid"].ToString() + "' and trantypeid=4";
            DataTable DTNum = DU.getdata(strsql);
            if (DTNum.Rows.Count > 0 && DTNum.Rows[0][0].ToString() != string.Empty)
            {
                strsql = "Select * from IVR_TRANFORMATNUM where TFOID='" + DTTfoid.Rows[0]["tfoid"].ToString() + "'";
                //strsql = "Select * from IVR_TRANFORMATNUM where TFOID='" + DTNum.Rows[0]["PoVoucherNo"].ToString() + "'";
                DataTable DT = DU.getdata(strsql);
                if (DT.Rows.Count > 0)
                {
                    if (DT.Rows[0]["NUMBERINGMETHOD"].ToString() == "True")
                    {
                        string SetZero = "";
                        int NumLength = Convert.ToInt32(DT.Rows[0]["NUMSTART"].ToString().Length);
                        int NumWidth = Convert.ToInt32(DT.Rows[0]["NUMDIGITS"].ToString());
                        int Diff = NumWidth - NumLength;
                        if (NumLength < NumWidth)
                        {
                            for (int i = 0; i < Diff; i++)
                            {
                                SetZero += "0";
                            }
                        }
                        double Povoucher = Convert.ToDouble(DTNum.Rows[0]["PoVoucherNo"].ToString());
                        MainVoucher = SetZero + (Povoucher + 1).ToString();
                        txtVoucher.Attributes.Add("onKeyPress", "return false");
                        txtVoucher.Attributes.Add("onKeyDown", "return false");
                    }
                    else
                    {
                        txtVoucher.Attributes.Add("onKeyPress", "return true");
                        txtVoucher.Attributes.Add("onKeyDown", "return true");
                    }
                    Prepix = DT.Rows[0]["NUMPREFIX"].ToString();
                    Suffix = DT.Rows[0]["NUMSUFFIX"].ToString();
                }
            }
            else
            {
                strsql = "Select * from IVR_TRANFORMATNUM where TFOID='" + DTTfoid.Rows[0]["tfoid"].ToString() + "'";
                //strsql = "Select * from IVR_TRANFORMATNUM where TFOID='" + DTNum.Rows[0]["PoVoucherNo"].ToString() + "'";
                DataTable DT = DU.getdata(strsql);
                if (DT.Rows.Count > 0)
                {
                    if (DT.Rows[0]["NUMBERINGMETHOD"].ToString() == "True")
                    {
                        string SetZero = "";
                        int NumLength = Convert.ToInt32(DT.Rows[0]["NUMSTART"].ToString().Length);
                        int NumWidth = Convert.ToInt32(DT.Rows[0]["NUMDIGITS"].ToString());
                        int Diff = NumWidth - NumLength;
                        if (NumLength < NumWidth)
                        {
                            for (int i = 0; i < Diff; i++)
                            {
                                SetZero += "0";
                            }
                        }
                        MainVoucher = SetZero + DT.Rows[0]["NUMSTART"].ToString();
                        txtVoucher.Attributes.Add("onKeyPress", "return false");
                        txtVoucher.Attributes.Add("onKeyDown", "return false");
                    }
                    else
                    {
                        txtVoucher.Attributes.Add("onKeyPress", "return true");
                        txtVoucher.Attributes.Add("onKeyDown", "return true");
                    }
                    Prepix = DT.Rows[0]["NUMPREFIX"].ToString();
                    Suffix = DT.Rows[0]["NUMSUFFIX"].ToString();
                }
            }
            txtPrefix.Text = Prepix.ToString();
            txtVoucher.Text = MainVoucher.ToString();
            txtSuffix.Text = Suffix.ToString();
        }
    }
    protected void Enable_TextBoxs()
    {
        strsql = "Select * from IVR_TRANFORMAT where trantype=4";
        DataTable DT = DU.getdata(strsql);
        if (DT.Rows.Count > 0)
        {
            if (DT.Rows[0]["PREPAREDBY"].ToString() == "True")
            {
                txtPreparedBy.Enabled = true;
                txtPreparedBy.BackColor = Color.White;
            }
            else
            {
                txtPreparedBy.Enabled = false;
                txtPreparedBy.BackColor = ColorTranslator.FromHtml("#d4d0c8");
            }
            if (DT.Rows[0]["CHECKEDBY"].ToString() == "True")
            {
                txtCheckedBy.Enabled = true;
                txtCheckedBy.BackColor = Color.White;
            }
            else
            {
                txtCheckedBy.Enabled = false;
                txtCheckedBy.BackColor = ColorTranslator.FromHtml("#d4d0c8");
            }
            if (DT.Rows[0]["AUTHSIGNATORY"].ToString() == "True")
            {
                txtSignatory.Enabled = true;
                txtSignatory.BackColor = Color.White;
            }
            else
            {
                txtSignatory.Enabled = false;
                txtSignatory.BackColor = ColorTranslator.FromHtml("#d4d0c8");
            }
            if (DT.Rows[0]["NARRATION"].ToString() == "True")
            {
                txtNarration.Enabled = true;
                txtNarration.BackColor = Color.White;
            }
            else
            {
                txtNarration.Enabled = false;
                txtNarration.BackColor = ColorTranslator.FromHtml("#d4d0c8");
            }
            if (DT.Rows[0]["REMARKS"].ToString() == "True")
            {
                txtRemark.Enabled = true;
                txtRemark.BackColor = Color.White;
            }
            else
            {
                txtRemark.Enabled = false;
                txtRemark.BackColor = ColorTranslator.FromHtml("#d4d0c8");
            }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["Poid"] != null && Convert.ToInt32(Request.QueryString["Currency"]) == 1)
        {
            #region Domestic
            try
            {
                PurchaseReceiveMain = ""; PurchaseReceiveItem = ""; PurchaseReceiveTotal = ""; PurchaseReceiveOthers = ""; PurchaseReceiveDelivery = "";
                InsertItemTranMain();
                int row = tblTaxItemLevel.Rows.Count;
                for (int i = 1; i < row; i++)
                {
                    TextBox txtqty = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtqty" + i.ToString());
                    HiddenField hidpartno = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hiPartId" + i.ToString());
                    HiddenField issueqty = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("issueqty" + i.ToString());
                    if (txtqty.Text != "" && Convert.ToInt32(txtqty.Text) > 0)
                    {
                        txtqty.Text = Convert.ToString(Convert.ToInt32(txtqty.Text) + Convert.ToInt32(issueqty.Value));
                        string sql = "Update ACC_PODETAILS set PurReceiveQty='" + txtqty.Text + "' where poid='" + Request.QueryString["Poid"].ToString() + "' and Itemid='" + hidpartno.Value + "'";
                        DU.executesql(sql);
                    }
                }
                string sqlse = "select sum(convert(int,(itemqty-PurReceiveQty)))as orders from ACC_PODETAILS where POID='" + Request.QueryString["Poid"].ToString() + "'";
                DataTable dt = DU.getdata(sqlse);
                if (dt.Rows.Count > 0)
                {
                    if (dt.Rows[0]["orders"].ToString() == "0")
                    {
                        string sqlup = "Update ACC_POMAIN set STAGES=6 Where POID='" + Request.QueryString["Poid"].ToString() + "'";
                        DU.executesql(sqlup);
                    }
                }
                //Creating Log for the Domestic Purchase Receive
                IP = Request.ServerVariables["REMOTE_ADDR"];
                PurchaseReceive = PurchaseReceiveMain + PurchaseReceiveItem + PurchaseReceiveTotal + PurchaseReceiveOthers + PurchaseReceiveDelivery;
                Log.SetPurchaseOrderReceiveLogs(Session["userid"].ToString(), Session["username"].ToString(), CommonLog.Type.ActivityLog.ToString(), PurchaseReceive, "PurInvoiceWithItemLevel.aspx", IP, System.DateTime.Now.ToString());

                ClearControl();
            }
            catch (Exception ex)
            {
                strsql = "Select Ident_Current('IVR_TRAN_MAIN') as TranId";
                DataTable DTDelete = DU.getdata(strsql);
                if (DTDelete.Rows.Count > 0)
                {
                    SqlParameter[] param = { new SqlParameter("@TRNID", DTDelete.Rows[0]["TranId"].ToString()) };
                    int rollback = DU.executeprocedure("USP_IVR_DELETE_PURCHASERECEIVE", param);
                    if (rollback > 0)
                    {
                        lblMsg.Text = "Please Re-Enter Purchase Receive Entries As Previous Entry Has Not been Saved.";
                        lblMsg.ForeColor = System.Drawing.Color.Red;
                    }
                }
            }
            #endregion
        }
        else
        {
            #region International
            try
            {
                PurchaseReceiveMain = ""; PurchaseReceiveItem = ""; PurchaseReceiveTotal = ""; PurchaseReceiveOthers = ""; PurchaseReceiveDelivery = "";
                InsertImportItemTranMain();
                int row = tblImportItemLevel.Rows.Count;
                for (int i = 1; i < row; i++)
                {
                    TextBox txtqty = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIQty" + i.ToString());
                    HiddenField hidpartno = (HiddenField)tblImportItemLevel.Rows[i].FindControl("hidIpartno" + i.ToString());
                    HiddenField issueqty = (HiddenField)tblImportItemLevel.Rows[i].FindControl("issueqty" + i.ToString());
                    if (txtqty.Text != "" && Convert.ToInt32(txtqty.Text) > 0)
                    {
                        txtqty.Text = (Convert.ToDouble(txtqty.Text) + Convert.ToDouble(issueqty.Value)).ToString();
                        string sql = "Update ACC_PODETAILS set PurReceiveQty='" + txtqty.Text + "' where poid='" + Request.QueryString["Poid"].ToString() + "' and Itemid='" + hidpartno.Value + "'";
                        DU.executesql(sql);
                    }
                }
                string sqlse = "select sum(convert(int,(itemqty-PurReceiveQty)))as orders from ACC_PODETAILS where POID='" + Request.QueryString["Poid"].ToString() + "'";
                DataTable dt = DU.getdata(sqlse);
                if (dt.Rows.Count > 0)
                {
                    if (dt.Rows[0]["orders"].ToString() == "0")
                    {
                        string sqlup = "Update ACC_POMAIN set STAGES=6 Where POID='" + Request.QueryString["Poid"].ToString() + "'";
                        DU.executesql(sqlup);
                    }
                }
                //Creating Log for the Domestic Purchase Receive
                IP = Request.ServerVariables["REMOTE_ADDR"];
                PurchaseReceive = PurchaseReceiveMain + PurchaseReceiveItem + PurchaseReceiveTotal + PurchaseReceiveOthers + PurchaseReceiveDelivery;
                Log.SetPurchaseOrderReceiveLogs(Session["userid"].ToString(), Session["username"].ToString(), CommonLog.Type.ActivityLog.ToString(), PurchaseReceive, "PurInvoiceWithItemLevel.aspx", IP, System.DateTime.Now.ToString());

                ClearControlInternational();
            }
            catch (Exception ex)
            {
                strsql = "Select Ident_Current('IVR_TRAN_MAIN') as TranId";
                DataTable DTDelete = DU.getdata(strsql);
                if (DTDelete.Rows.Count > 0)
                {
                    SqlParameter[] param = { new SqlParameter("@TRNID", DTDelete.Rows[0]["TranId"].ToString()) };
                    int rollback = DU.executeprocedure("USP_IVR_DELETE_PURCHASERECEIVE", param);
                    if (rollback > 0)
                    {
                        lblMsg.Text = "Please Re-Enter Purchase Receive Entries As Previous Entry Has Not been Saved.";
                        lblMsg.ForeColor = System.Drawing.Color.Red;
                    }
                }
            }
            #endregion
        }
        Response.Redirect("PurchaseReceived/PurchasedReceived.aspx?action=addnew");
    }
    private void ClearControl()
    {
        int rowCount = 0;
        if (hidControlTblItems.Value != "")
        {
            rowCount = Convert.ToInt32(hidControlTblItems.Value);
        }
        for (int i = 1; i <= rowCount; i++)
        {
            TextBox txtpartno = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtpartno" + i.ToString());
            //HiddenField issueqty = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("issueqty" + i.ToString());
            //HiddenField hidpartno = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hiPartId" + i.ToString());
            TextBox txtdesc = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtdesc" + i.ToString());
            TextBox txtqty = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtqty" + i.ToString());
            //HiddenField hiddenqty = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidqty" + i.ToString());
            DropDownList ddlvatcst = (DropDownList)tblTaxItemLevel.Rows[i].FindControl("ddlsalestax" + i.ToString());
            //HiddenField hidunitprice = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidunitprice" + i.ToString());
            TextBox txtunitprice = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtunitprice" + i.ToString());
            //HiddenField hiddenQty = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidqty" + i.ToString());
            //HiddenField hidLocationId = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidLocationId" + i.ToString());
            TextBox txtsubamount = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtsubamount" + i.ToString());
            DropDownList ddlSalesTax = (DropDownList)tblTaxItemLevel.Rows[i].FindControl("ddlsalestax" + i.ToString());
            //HiddenField hidTaxRate = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidsalestax" + i.ToString());
            TextBox txtvatcstamt = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtvatcstamt" + i.ToString());
            TextBox txtfreightD = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtfreight" + i.ToString());
            TextBox txtpackagingD = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtpackaging" + i.ToString());
            TextBox txtinsuranceD = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtinsurance" + i.ToString());
            TextBox txttotallanded = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txttotallanded" + i.ToString());
            TextBox txttotalinventcost = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txttotalinventcost" + i.ToString());
            //HiddenField hidUOMID = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidUOMID" + i.ToString());
            //HiddenField hidRateIncTax = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidRateIncTax" + i.ToString());


            txtpartno.Text = ""; txtvatcstamt.Text = "";
            txtdesc.Text = ""; txtfreightD.Text = "";
            txtqty.Text = ""; txtpackagingD.Text = "";
            txtunitprice.Text = ""; txtinsuranceD.Text = "";
            ddlvatcst.SelectedValue = "0"; txttotallanded.Text = "";
            txtsubamount.Text = ""; txttotalinventcost.Text = "";
            ddlSalesTax.SelectedValue = "0";
        }
        txtTotalQuantity.Text = ""; txtTaxableAmt.Text = ""; txtPostTaxTotal.Text = ""; txtpackaging.Text = ""; txtRoundoff.Text = "";
        txtGrossAmount.Text = ""; txtVat.Text = ""; txtfreight.Text = ""; txtinsurance.Text = ""; txtGrandTotal.Text = "";
    }//for domestic
    private void ClearControlInternational()//For Internationl
    {
        int intCount = Convert.ToInt32(hidimportTblItems.Value);
        for (int i = 1; i <= intCount; i++)
        {
            TextBox txtpartno = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIpartno" + i.ToString());
            TextBox txtdesc = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIdesc" + i.ToString());
            DropDownList ddlcoo = (DropDownList)tblImportItemLevel.Rows[i].FindControl("ddlIcoo" + i.ToString());
            TextBox txtunitprice = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIUnitPrice" + i.ToString());
            TextBox txtqty = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIQty" + i.ToString());
            TextBox txtextendedvalue = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIExtendVal" + i.ToString());
            TextBox txtunitpriceINR = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIUnitPriceINR" + i.ToString());
            TextBox txtinvoicevalue = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIInvoiceVal" + i.ToString());
            TextBox txtassesvalue = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIAsseval" + i.ToString());
            TextBox txteducessCVD = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIEducess" + i.ToString());
            TextBox txtHeducessCVD = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIHEducess" + i.ToString());
            TextBox txttotalduty = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtITotalduty" + i.ToString());
            TextBox txtcustomcess = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtICustomedu" + i.ToString());
            TextBox txtHeduCustomcess = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtICustomHSedu" + i.ToString());
            TextBox txtGrandtotal = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIGrandTotal" + i.ToString());
            TextBox txtclearingfreight = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIClearFreight" + i.ToString());
            TextBox txttotallandedcost = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtILandedCost" + i.ToString());
            TextBox txtInventoryCost = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIInventCost" + i.ToString());
            TextBox txtaddlduty = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIAddDuty" + i.ToString());
            DropDownList ddladdlduty = (DropDownList)tblImportItemLevel.Rows[i].FindControl("ddlIAddDuty" + i.ToString());
            DropDownList ddlCustomHSEduCess = (DropDownList)tblImportItemLevel.Rows[i].FindControl("ddlHSeducessoncustom" + i.ToString());
            DropDownList ddlCustomEducess = (DropDownList)tblImportItemLevel.Rows[i].FindControl("ddleducessoncustom" + i.ToString());
            DropDownList ddlHigherEducess = (DropDownList)tblImportItemLevel.Rows[i].FindControl("ddlHeducessoncvd" + i.ToString());
            DropDownList ddleducationcessonCVD = (DropDownList)tblImportItemLevel.Rows[i].FindControl("ddleducessoncvd" + i.ToString());
            TextBox txtcvd = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtICVD" + i.ToString());
            DropDownList ddlcvd = (DropDownList)tblImportItemLevel.Rows[i].FindControl("ddlICVD" + i.ToString());
            DropDownList ddlbasiccustom = (DropDownList)tblImportItemLevel.Rows[i].FindControl("ddlIBasicCust" + i.ToString());
            TextBox txtBasiccustom = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIBasicCust" + i.ToString());

            txtpartno.Text = ""; txtdesc.Text = ""; txtunitprice.Text = ""; txtqty.Text = ""; txtextendedvalue.Text = "";
            txtunitpriceINR.Text = ""; txtinvoicevalue.Text = ""; txtassesvalue.Text = ""; txteducessCVD.Text = "";
            txtHeducessCVD.Text = ""; txttotalduty.Text = ""; txtcustomcess.Text = ""; txtHeduCustomcess.Text = ""; txtGrandtotal.Text = ""; txtclearingfreight.Text = "";
            txttotallandedcost.Text = ""; txtInventoryCost.Text = ""; txtaddlduty.Text = ""; ddlcoo.SelectedValue = "0"; ddladdlduty.SelectedValue = "0"; ddlCustomHSEduCess.SelectedValue = "0";
            ddlCustomEducess.SelectedValue = "0"; ddlHigherEducess.SelectedValue = "0"; ddleducationcessonCVD.SelectedValue = "0"; txtcvd.Text = ""; ddlcvd.SelectedValue = "0";
            ddlbasiccustom.SelectedValue = "0"; txtBasiccustom.Text = "";
        }
        txttotalitemquantity.Text = ""; txtGrossAmount.Text = ""; txtTaxable.Text = ""; txtClearingfreight.Text = ""; txtPackage.Text = ""; txtInsur.Text = "";
        txtAssesValue.Text = ""; txtBasicCustomDuty.Text = ""; txtCvd.Text = ""; txtEcessonCVD.Text = ""; txtSHECessOnCVD.Text = "";
        txtCustomeduCess.Text = ""; txtSHCustomEduCess.Text = ""; txtAddlDuty.Text = ""; txtotherCharges.Text = ""; txtDutyPayable.Text = ""; txtGross.Text = "";
    }
    protected void InsertItemTranMain()
    {
        string strFinYear = string.Empty;
        string strTransDate = string.Empty;
        string strRefDate = "01/01/1900";
        string strPurRecDate = string.Empty;
        string strEffectiveDate = string.Format("{0:MM/dd/yyyy}", System.DateTime.Now).ToString();
        strsql = "Select * from MAS_FINYEAR";
        DataTable DTFinYear = DU.getdata(strsql);
        if (DTFinYear.Rows.Count > 0)
        {
            strFinYear = DTFinYear.Rows[0]["FINYEAR"].ToString();
        }
        if (txtDate.Text.ToString() != string.Empty)
        {
            string[] str = txtDate.Text.ToString().Split('/');
            strTransDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
        }
        if (TxtPurchaseReceiveDate.Text.ToString() != string.Empty)
        {
            string[] Purstr = TxtPurchaseReceiveDate.Text.ToString().Split('/');
            strPurRecDate = Purstr[1].ToString() + "/" + Purstr[0].ToString() + "/" + Purstr[2].ToString();
        }
        if (txtexcrate.Text == "")
        {
            txtexcrate.Text = "1";
        }
        SqlParameter[] sparam ={
                                    //new SqlParameter("@TRANREFERENCEID",strRefId.ToString()),
                                    new SqlParameter("@TRANTYPEID","4"),
                                    new SqlParameter("@FINYEAR",strFinYear.ToString()),
                                    new SqlParameter("@POID",Request.QueryString["Poid"].ToString()),
                                    new SqlParameter("@INVOICENO",txtInvoiceNo.Text.Trim()),
                                    new SqlParameter("@TFOID",hidBillformatId.Value.ToString()),
                                    new SqlParameter("@TRNNUM",txtVoucher.Text.Trim()),
                                    new SqlParameter("@TRNDATE",strTransDate.ToString()),
                                    new SqlParameter("@VENDCUST_LID",hidSupplierID.Value.ToString()),
                                    new SqlParameter("@TAX_MAINCLASSID",ddlTaxGroup.SelectedValue),
                                    new SqlParameter("@TRNSTATUS","1"),
                                    new SqlParameter("@EFFECTIVEDATE",strEffectiveDate.ToString()),
                                    new SqlParameter("@MODEOFPAY",rbtCashCredit.SelectedValue),
                                    new SqlParameter("@CREDITPERIOD",txtCreditDay.Text.Trim()),
                                    new SqlParameter("@REFNUM","Bill-Ref"),
                                    //new SqlParameter("@REFDATE",strRefDate.ToString()),
                                    new SqlParameter("@SURCHARGE","0"),
                                    new SqlParameter("@CNAME",Session["username"].ToString()),
                                    new SqlParameter("@LEASEDTYPE",ddlleasedtype.SelectedItem.ToString()),
                                    new SqlParameter("@CURRENCY",ddlcurrency.SelectedValue),
                                    new SqlParameter("@EXCHANGERATE",Convert.ToDecimal(txtexcrate.Text)),
                                    new SqlParameter("@LID",templocationid.Value),
                                    new SqlParameter("@foliono",txtfolioNo.Text),
                                    new SqlParameter("@TotalInvoiceAmt",Convert.ToDecimal(txtTotalInvoiceValue.Text)),
                                    new SqlParameter("@PurchaseRecDate",strPurRecDate.ToString())
                                };
        //Forlog
        PurchaseReceiveMain = "InvoiceNo=" + txtInvoiceNo.Text + ",VoucherNo=" + txtVoucher.Text + ",TransactionDate=" + strTransDate.ToString() + ",TaxGroup=" + ddlTaxGroup.SelectedItem + ",LeasedType=" + ddlleasedtype.SelectedItem + ",Currency=" + ddlcurrency.SelectedItem + ",ExchangeRate=" + Convert.ToDecimal(txtexcrate.Text) + ",FolioNo=" + txtfolioNo.Text + ",TotalInvoiceAmt=" + Convert.ToDecimal(txtTotalInvoiceValue.Text) + ",PurchaseReceiveDate=" + strPurRecDate.ToString() + ",";
        int intResult = DU.executeprocedure("USP_IVR_SaveTranMain", sparam);
        if (intResult > 0)
        {
            strsql = "Select Ident_Current('IVR_TRAN_MAIN') as TranId";
            DataTable DTTranid = DU.getdata(strsql);
            if (DTTranid.Rows.Count > 0)
            {
                InsertItemTranItem(DTTranid.Rows[0]["TranId"].ToString());
                InsertItemTranTotal(DTTranid.Rows[0]["TranId"].ToString());
                InsertTranDelivery(DTTranid.Rows[0]["TranId"].ToString());
                InsertTranOthers(DTTranid.Rows[0]["TranId"].ToString());
            }
            lblMsg.Text = "Stock Updated....";
            lblMsg.ForeColor = System.Drawing.Color.Black;
        }
    }
    protected void InsertItemTranItem(string strTranId)
    {
        if (strTranId.ToString() != string.Empty)
        {
            int intResult = 0; int status = 0;
            int intCount = Convert.ToInt32(hidControlTblItems.Value);

            for (int i = 1; i <= intCount; i++)
            {
                //TextBox txtRate = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtRate" + i.ToString());
                //HiddenField hidItemId = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidItemId" + i.ToString());
                //HiddenField hidUnitId = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidUnitId" + i.ToString());
                //TextBox txtReceivedQty = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtReceivedQty" + i.ToString());
                //TextBox txtGrossAmt = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtGrossAmt" + i.ToString());
                //DropDownList ddlTaxType = (DropDownList)tblTaxItemLevel.Rows[i].FindControl("ddlTaxType" + i.ToString());
                //HiddenField hidTaxRate = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidTaxRate" + i.ToString());
                //TextBox txtTaxAmt = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtTaxAmt" + i.ToString());
                //TextBox txtAmountPayable = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtAmountPayable" + i.ToString());
                //DropDownList ddlPurchaseLedger = (DropDownList)tblTaxItemLevel.Rows[i].FindControl("ddlPurchaseLedger" + i.ToString());
                //DropDownList ddlTaxLedger = (DropDownList)tblTaxItemLevel.Rows[i].FindControl("ddlTaxLedger" + i.ToString());

                TextBox txtpartno = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtpartno" + i.ToString());
                HiddenField hidpartno = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hiPartId" + i.ToString());
                TextBox txtdesc = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtdesc" + i.ToString());
                TextBox txtunitprice = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtunitprice" + i.ToString());
                TextBox txtqty = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtqty" + i.ToString());
                HiddenField hiddenQty = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidqty" + i.ToString());
                HiddenField hidLocationId = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidLocationId" + i.ToString());
                HiddenField hidSalestaxID = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidsalestaxID" + i.ToString());
                TextBox txtsubamount = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtsubamount" + i.ToString());
                DropDownList ddlSalesTax = (DropDownList)tblTaxItemLevel.Rows[i].FindControl("ddlsalestax" + i.ToString());
                HiddenField hidTaxRate = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidsalestax" + i.ToString());
                TextBox txtvatcstamt = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtvatcstamt" + i.ToString());
                TextBox txtfreight = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtfreight" + i.ToString());
                TextBox txtpackaging = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtpackaging" + i.ToString());
                TextBox txtinsurance = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtinsurance" + i.ToString());
                TextBox txttotallanded = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txttotallanded" + i.ToString());
                TextBox txttotalinventcost = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txttotalinventcost" + i.ToString());
                TextBox txtServiceTax = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtServiceTax" + i.ToString());
                TextBox txtServiceTaxAmount = (TextBox)tblTaxItemLevel.Rows[i].FindControl("txtServiceTaxAmount" + i.ToString());
                HiddenField hidUOMID = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidUOMID" + i.ToString());
                HiddenField hidRateIncTax = (HiddenField)tblTaxItemLevel.Rows[i].FindControl("hidRateIncTax" + i.ToString());


                if (hidTaxRate.Value.ToString() == string.Empty)
                {
                    hidTaxRate.Value = "0";
                }
                if (txtunitprice.Text != "" && txtqty.Text != "" && Convert.ToInt32(txtqty.Text) > 0)
                {
                    SqlParameter[] param = {new SqlParameter("@TRNID",strTranId.ToString()),
                                            new SqlParameter("@ITMID",hidpartno.Value.Trim()),
                                            new SqlParameter("@ADDNDESC",txtdesc.Text.Trim()),
                                            new SqlParameter("@RATE",Convert.ToDecimal(txtunitprice.Text)),
                                            new SqlParameter("@ITMQTY",Convert.ToDecimal(txtqty.Text)),
                                            new SqlParameter("@NETAMT",Convert.ToDecimal(txtsubamount.Text)),
                                            new SqlParameter("@TAXPER",Convert.ToDecimal(hidTaxRate.Value)),
                                            new SqlParameter("@TAXAMT",Convert.ToDecimal(txtvatcstamt.Text)),
                                            new SqlParameter("@FREIGHT",txtfreight.Text),
                                            new SqlParameter("@PACKAGING",txtpackaging.Text),
                                            new SqlParameter("@INSURANCE",txtinsurance.Text),
                                            new SqlParameter("@ITMAMT",Convert.ToDecimal(txttotallanded.Text)),
                                            //new SqlParameter("@TOTALINVENTCOST",txttotalinventcost.Text),
                                            new SqlParameter("@UOMID",hidUOMID.Value),
                                            new SqlParameter("@RATEINCL",Convert.ToDouble(hidRateIncTax.Value)),                                            
                                            new SqlParameter("@TAX_TXMASID",hidSalestaxID.Value),            
                                            new SqlParameter("@ALTITMQTY","0"),//Alternet item Qty Currently Not enable from Transaction Setting
                                            new SqlParameter("@GROSSAMT",Convert.ToDecimal(txttotallanded.Text)),
                                            new SqlParameter("@ServiceTax",Convert.ToDecimal(txtServiceTax.Text)),
                                            new SqlParameter("@ServiceTaxAmount",Convert.ToDecimal(txtServiceTaxAmount.Text)),
                                            new SqlParameter("@DISCPER","0"),
                                            new SqlParameter("@DISCAMT","0"),
                                            new SqlParameter("@CENVATPER","0"),
                                            new SqlParameter("@CENVATAMT","0"),
                                            new SqlParameter("@PRIMARYCESSPER","0"),
                                            new SqlParameter("@PRIMARYCESSAMT","0"),
                                            new SqlParameter("@HIGHERCESSPER","0"),
                                            new SqlParameter("@HIGHERCESSAMT","0"),
                                            new SqlParameter("@ITMPENDINGQTY","0"),
                                            new SqlParameter("@ITMAMT_LID","0"),
                                            new SqlParameter("@TAXAMT_LID","0"),
                                            new SqlParameter("@EntryType","PUR"),
                                            new SqlParameter("@IssueQTY","0"),
                                            new SqlParameter("@ReturnQty","0")
                                            };
                    intResult = DU.executeprocedure("USP_IVR_SaveTranItem", param);
                    //Creating log

                    PurchaseReceiveItem += "ItemID=" + hidpartno.Value + ",ItemName=" + txtdesc.Text + ",Rate=" + Convert.ToDecimal(txtunitprice.Text) + ",ItemQty=" + Convert.ToDecimal(txtqty.Text) +
                        ",SubAmount=" + Convert.ToDecimal(txtsubamount.Text) + ",TaxRate=" + Convert.ToDecimal(hidTaxRate.Value) + ",TaxAmount=" + Convert.ToDecimal(txtvatcstamt.Text) + ",Freight=" + txtfreight.Text +
                        ",Packaging=" + txtpackaging.Text + ",Insurance=" + txtinsurance.Text + ",TotalLandedCost=" + Convert.ToDecimal(txttotallanded.Text) + ",TotalInventCost=" + txttotalinventcost.Text +
                        ",RateIncTax=" + Convert.ToDouble(hidRateIncTax.Value) + ",GrossAmt=" + Convert.ToDecimal(txttotallanded.Text) + ",ServiceTax=" + Convert.ToDecimal(txtServiceTax.Text) + ",ServiceTaxAmt=" + Convert.ToDecimal(txtServiceTaxAmount.Text) + ",";
                }
                if (intResult > 0)
                {
                    strsql = "Select Ident_Current('IVR_TRAN_ITEM') as TITID";
                    DataTable DTTranid = DU.getdata(strsql);
                    if (DTTranid.Rows.Count > 0)
                    {
                        // InsertItemTranDetails(strTranId, DTTranid.Rows[0]["TITID"].ToString(), i);
                    }
                    intResult = 0;
                }
            }
        }
    }
    protected void InsertItemTranTotal(string strTranId)
    {
        if (strTranId.ToString() != string.Empty)
        {
            int intResult = 0;
            SqlParameter[] sparam ={
                            new SqlParameter("@TRNID",strTranId.ToString()),
                            new SqlParameter("@TOTALITEMQTY",txtTotalQuantity.Text),
                            new SqlParameter("@ITEMTOTAL",Convert.ToDecimal(txtGrossAmount.Text)),
                            new SqlParameter("@TAXABLEAMT",Convert.ToDecimal(txtTaxableAmt.Text)),
                            new SqlParameter("@TAXAMT",txtVat.Text),
                            new SqlParameter("@POSTTAXTOTAL",txtPostTaxTotal.Text),
                            new SqlParameter("@FREIGHT",txtfreight.Text),
                            new SqlParameter("@PACKAGING",txtpackaging.Text),
                            new SqlParameter("@INSURANCE",txtinsurance.Text),
                            new SqlParameter("@RNDOFFAMT",txtRoundoff.Text),
                            //new SqlParameter("@RNDOFFAMT_LID",ddlRoundOff.SelectedValue),
                            new SqlParameter("@TRNTOTAL",Convert.ToDecimal(txtGrandTotal.Text))
                        };
            intResult = DU.executeprocedure("USP_IVR_SaveTranTotal", sparam);
            //For Log
            PurchaseReceiveTotal = "TotalItemQty=" + txtTotalQuantity.Text + ",TotalGrossAmt=" + Convert.ToDecimal(txtGrossAmount.Text) + ",TaxableAmt=" + Convert.ToDecimal(txtTaxableAmt.Text) + ",Freight=" + txtfreight.Text + ",Packaging=" + txtpackaging.Text + ",Insurance=" + txtinsurance.Text + ",GrandTotal=" + Convert.ToDecimal(txtGrandTotal.Text) + ",";
        }
    }
    protected void InsertTranOthers(string tranId)
    {
        if (tranId.ToString() != string.Empty)
        {
            SqlParameter[] sparam =
                                     {
                                         new SqlParameter("@TRNID",tranId.ToString()),
                                         new SqlParameter("@PREPAREDBY",txtPreparedBy.Text.Trim()),
                                         new SqlParameter("@CHECKEDBY",txtCheckedBy.Text.Trim()),
                                         new SqlParameter("@AUTHRSDSIGNAT",txtSignatory.Text.Trim()),
                                         new SqlParameter("@NARRATION",txtNarration.Text.Trim()),
                                         new SqlParameter("@REMARKS",txtRemark.Text.Trim())
                                     };
            DU.executeprocedure("USP_IVR_SaveTranOthers", sparam);
            //For Log
            PurchaseReceiveOthers = "PreparedBy=" + txtPreparedBy.Text + ",CheckedBy=" + txtCheckedBy.Text + ",AutherizedSignatory=" + txtSignatory.Text + ",Narration=" + txtNarration.Text + ",Remarks=" + txtRemark.Text + ",";
        }
    }
    protected void InsertTranDelivery(string tranId)
    {
        if (tranId.ToString() != string.Empty)
        {
            //string strDeliveryDate = "1/1/1900";
            string strDeliveryDate = null;
            if (txtDeliveryDate.Text != string.Empty)
            {
                string[] str = txtDeliveryDate.Text.ToString().Split('/');
                strDeliveryDate = str[1] + "/" + str[0] + "/" + str[2];
            }
            SqlParameter[] sparam =
                                     {
                                         new SqlParameter("@TRNID",tranId.ToString()),
                                         new SqlParameter("@MODEOFDELIVERY",txtDeliveryMode.Text.Trim()),
                                         new SqlParameter("@DELIVERYDATE",strDeliveryDate) ,
                                         new SqlParameter("@DOCUMENTNUM",txtDocumentNo.Text.Trim()),
                                         new SqlParameter("@VEHICLENUM",txtVehicle.Text.Trim()),
                                         new SqlParameter("@TRANSPORTNAME",txtTransporter.Text.Trim()),
                                         new SqlParameter("@BILLINGADDRESS",txtBillAddress.Text),
                                         new SqlParameter("@DELIVERYADDRESS",txtDeliveryAdd.Text)
                                     };
            DU.executeprocedure("USP_IVR_SaveTranDelivery", sparam);
            //ForLog
            PurchaseReceiveDelivery = "ModeOfDelivery=" + txtDeliveryMode.Text + ",BillingAddress=" + txtBillAddress.Text + ",DeliveryAddress=" + txtDeliveryAdd.Text + ",DeliveryDate=" + strDeliveryDate + ",DocumentNo=" + txtDocumentNo.Text + ",VehicalNo=" + txtVehicle.Text + ",TransporterName=" + txtTransporter.Text;
        }
    }
    //for the import
    protected void InsertImportItemTranMain()
    {
        string strFinYear = string.Empty;
        string strTransDate = string.Empty;
        string strPurRecDate = string.Empty;
        //string strRefDate = "01/01/1900";
        string strEffectiveDate = string.Format("{0:MM/dd/yyyy}", System.DateTime.Now).ToString();
        strsql = "Select * from MAS_FINYEAR";
        DataTable DTFinYear = DU.getdata(strsql);
        if (DTFinYear.Rows.Count > 0)
        {
            strFinYear = DTFinYear.Rows[0]["FINYEAR"].ToString();
        }
        if (txtDate.Text.ToString() != string.Empty)
        {
            string[] str = txtDate.Text.ToString().Split('/');
            strTransDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
        }
        if (TxtPurchaseReceiveDate.Text.ToString() != string.Empty)
        {
            string[] Purstr = TxtPurchaseReceiveDate.Text.ToString().Split('/');
            strPurRecDate = Purstr[1].ToString() + "/" + Purstr[0].ToString() + "/" + Purstr[2].ToString();
        }
        if (txtexcrate.Text == "")
        {
            txtexcrate.Text = "1";
        }
        SqlParameter[] sparam ={
                                    //new SqlParameter("@TRANREFERENCEID",strRefId.ToString()),
                                    new SqlParameter("@TRANTYPEID","4"),
                                    new SqlParameter("@FINYEAR",strFinYear.ToString()),
                                    new SqlParameter("@POID",Request.QueryString["Poid"].ToString()),
                                    new SqlParameter("@INVOICENO",txtInvoiceNo.Text.Trim()),
                                    new SqlParameter("@TFOID",hidBillformatId.Value.ToString()),
                                    new SqlParameter("@TRNNUM",txtVoucher.Text.Trim()),
                                    new SqlParameter("@TRNDATE",strTransDate.ToString()),
                                    new SqlParameter("@VENDCUST_LID",hidSupplierID.Value.ToString()),
                                    new SqlParameter("@TAX_MAINCLASSID",ddlTaxGroup.SelectedValue),
                                    new SqlParameter("@TRNSTATUS","1"),
                                    new SqlParameter("@EFFECTIVEDATE",strEffectiveDate.ToString()),
                                    new SqlParameter("@MODEOFPAY",rbtCashCredit.SelectedValue),
                                    new SqlParameter("@CREDITPERIOD",txtCreditDay.Text.Trim()),
                                    new SqlParameter("@REFNUM","Bill-Ref"),
                                    //new SqlParameter("@REFDATE",strRefDate.ToString()),
                                    new SqlParameter("@SURCHARGE","0"),
                                    new SqlParameter("@CNAME",Session["username"].ToString()),
                                    new SqlParameter("@LEASEDTYPE",ddlleasedtype.SelectedItem.ToString()),
                                    new SqlParameter("@CURRENCY",ddlcurrency.SelectedValue),
                                    new SqlParameter("@EXCHANGERATE",Convert.ToDecimal(txtexcrate.Text)),
                                    new SqlParameter("@LID",templocationid.Value),
                                    new SqlParameter("@foliono",txtfolioNo.Text),
                                    new SqlParameter("@TotalInvoiceAmt",Convert.ToDecimal(txtTotalInvoiceValue.Text)),
                                    new SqlParameter("@PurchaseRecDate",strPurRecDate.ToString())
                                };
        int intResult = DU.executeprocedure("USP_IVR_SaveTranMain", sparam);
        //Forlog
        PurchaseReceiveMain = "InvoiceNo=" + txtInvoiceNo.Text + ",VoucherNo=" + txtVoucher.Text + ",TransactionDate=" + strTransDate.ToString() + ",TaxGroup=" + ddlTaxGroup.SelectedItem + ",LeasedType=" + ddlleasedtype.SelectedItem + ",Currency=" + ddlcurrency.SelectedItem + ",ExchangeRate=" + Convert.ToDecimal(txtexcrate.Text) + ",FolioNo=" + txtfolioNo.Text + ",TotalInvoiceAmt=" + Convert.ToDecimal(txtTotalInvoiceValue.Text) + ",PurchaseReceiveDate=" + strPurRecDate.ToString() + ",";

        if (intResult > 0)
        {
            strsql = "Select Ident_Current('IVR_TRAN_MAIN') as TranId";
            DataTable DTTranid = DU.getdata(strsql);
            if (DTTranid.Rows.Count > 0)
            {
                InsertImportItemTranItem(DTTranid.Rows[0]["TranId"].ToString());
                InsertImportItemTranTotal(DTTranid.Rows[0]["TranId"].ToString());
                InsertImportTranDelivery(DTTranid.Rows[0]["TranId"].ToString());
                InsertImportTranOthers(DTTranid.Rows[0]["TranId"].ToString());
            }
            lblMsg.Text = "Stock Updated....";
            lblMsg.ForeColor = System.Drawing.Color.Black;
        }

    }
    protected void InsertImportItemTranItem(string strTranId)
    {
        if (strTranId.ToString() != string.Empty)
        {
            int intResult = 0; int status = 0;
            int intCount = Convert.ToInt32(hidimportTblItems.Value);

            for (int i = 1; i <= intCount; i++)
            {
                TextBox txtpartno = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIpartno" + i.ToString());
                HiddenField hidpartno = (HiddenField)tblImportItemLevel.Rows[i].FindControl("hidIpartno" + i.ToString());
                TextBox txtdesc = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIdesc" + i.ToString());
                DropDownList ddlcoo = (DropDownList)tblImportItemLevel.Rows[i].FindControl("ddlIcoo" + i.ToString());
                TextBox txtunitprice = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIUnitPrice" + i.ToString());
                TextBox txtqty = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIQty" + i.ToString());
                TextBox txtextendedvalue = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIExtendVal" + i.ToString());
                TextBox txtunitpriceINR = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIUnitPriceINR" + i.ToString());
                TextBox txtinvoicevalue = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIInvoiceVal" + i.ToString());
                TextBox txtassesvalue = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIAsseval" + i.ToString());
                HiddenField hidBasicCustomDuty = (HiddenField)tblImportItemLevel.Rows[i].FindControl("hidIBasicCust" + i.ToString());
                HiddenField hidCVD = (HiddenField)tblImportItemLevel.Rows[i].FindControl("hidICVD" + i.ToString());
                TextBox txteducessCVD = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIEducess" + i.ToString());
                TextBox txtHeducessCVD = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIHEducess" + i.ToString());
                TextBox txttotalduty = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtITotalduty" + i.ToString());
                TextBox txtcustomcess = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtICustomedu" + i.ToString());
                TextBox txtHeduCustomcess = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtICustomHSedu" + i.ToString());
                HiddenField hidAdditionalduty = (HiddenField)tblImportItemLevel.Rows[i].FindControl("hidIAddDuty" + i.ToString());
                TextBox txtGrandtotal = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIGrandTotal" + i.ToString());
                TextBox txtclearingfreight = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIClearFreight" + i.ToString());
                TextBox txttotallandedcost = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtILandedCost" + i.ToString());
                TextBox txtInventoryCost = (TextBox)tblImportItemLevel.Rows[i].FindControl("txtIInventCost" + i.ToString());
                HiddenField hidUOMID = (HiddenField)tblImportItemLevel.Rows[i].FindControl("hidUOMID" + i.ToString());
                HiddenField hidRateInc = (HiddenField)tblImportItemLevel.Rows[i].FindControl("hidRateInc" + i.ToString());

                //if (hidTaxRate.Value.ToString() == string.Empty)
                //{
                //    hidTaxRate.Value = "0";
                //}
                if (txtunitprice.Text != "" && txtqty.Text != "" && Convert.ToInt32(txtqty.Text) > 0)
                {
                    SqlParameter[] param = {new SqlParameter("@TRNID",strTranId.ToString()),
                                            new SqlParameter("@ITMID",hidpartno.Value.Trim()),
                                            new SqlParameter("@ADDNDESC",txtdesc.Text.Trim()),
                                            new SqlParameter("@RATE",Convert.ToDecimal(txtunitprice.Text)),
                                            new SqlParameter("@ITMQTY",Convert.ToDecimal(txtqty.Text)),                                      
                                            new SqlParameter("@FREIGHT",txtclearingfreight.Text),                                     
                                            new SqlParameter("@ITMAMT",txttotallandedcost.Text),
                                            //new SqlParameter("@TOTALINVENTCOST",txtInventoryCost.Text),
                                            new SqlParameter("@COO",ddlcoo.SelectedValue),
                                            new SqlParameter("@EXTENDEDVALUE",txtextendedvalue.Text),
                                            new SqlParameter("@UNITPRICEINR",txtunitpriceINR.Text),
                                            new SqlParameter("@INVOICEVALUE",txtinvoicevalue.Text),
                                            new SqlParameter("@ACCESSVALUE",txtassesvalue.Text),
                                            new SqlParameter("@BASICCUSTOMDUTY",hidBasicCustomDuty.Value),
                                            new SqlParameter("@CVD",hidCVD.Value),
                                            new SqlParameter("@EDUCESSONCVD",txteducessCVD.Text),
                                            new SqlParameter("@HEDUCESSONCVD",txtHeducessCVD.Text),
                                            new SqlParameter("@TOTALDUTY",txttotalduty.Text),
                                            new SqlParameter("@CUSTOMEDUCATIONAL",txtcustomcess.Text),
                                            new SqlParameter("@CUSTOMHEDU",txtHeduCustomcess.Text),
                                            new SqlParameter("@ADDDUTY",hidAdditionalduty.Value),
                                            new SqlParameter("@GRANDTOTALDUTY",txtGrandtotal.Text),
                                            new SqlParameter("@UOMID",hidUOMID.Value),
                                            new SqlParameter("@RATEINCL",hidRateInc.Value),
                                            new SqlParameter("@ALTITMQTY","0"),//Alternet item Qty Currently Not enable from Transaction Setting
                                            new SqlParameter("@GROSSAMT",txttotallandedcost.Text),
                                            new SqlParameter("@DISCPER","0"),
                                            new SqlParameter("@DISCAMT","0"),
                                            new SqlParameter("@CENVATPER","0"),
                                            new SqlParameter("@CENVATAMT","0"),
                                            new SqlParameter("@PRIMARYCESSPER","0"),
                                            new SqlParameter("@PRIMARYCESSAMT","0"),
                                            new SqlParameter("@HIGHERCESSPER","0"),
                                            new SqlParameter("@HIGHERCESSAMT","0"),
                                            new SqlParameter("@ITMPENDINGQTY","0"),
                                            new SqlParameter("@ITMAMT_LID","0"),
                                            new SqlParameter("@TAXAMT_LID","0"),
                                            new SqlParameter("@EntryType","PUR"),
                                            new SqlParameter("@IssueQty","0"),
                                            new SqlParameter("@ReturnQty","0")
                                            };
                    intResult = DU.executeprocedure("USP_IVR_IMPORT_SaveTranItem", param);
                    //ForLog
                    PurchaseReceiveItem += "ItemID=" + hidpartno.Value + ",ItemName=" + txtdesc.Text + ",Rate=" + Convert.ToDecimal(txtunitprice.Text) + ",ItemQty=" + Convert.ToDecimal(txtqty.Text) +
                        "Freight=" + txtclearingfreight.Text + ",TotalLandedCost=" + txttotallandedcost.Text + ",TotalInventoryCost=" + txtInventoryCost.Text + ",Coo=" + ddlcoo.SelectedItem +
                        ",ExtendeValue=" + txtextendedvalue.Text + ",UnitPriceINR=" + txtunitpriceINR.Text + ",InvoiceValue=" + txtinvoicevalue.Text + ",AccessValue=" + txtassesvalue.Text +
                        ",BasicCustomDuty=" + hidBasicCustomDuty.Value + ",CVD=" + hidCVD.Value + ",EduCessONCVD=" + txteducessCVD.Text + "HigherEduCessONCVD" + txtHeducessCVD.Text +
                        ",TotalDuty=" + txttotalduty.Text + ",CustomeEducationalCess=" + txtcustomcess.Text + ",CustomeHigherEduCess" + txtHeduCustomcess.Text +
                        ",AdditionalDuty=" + hidAdditionalduty.Value + ",GrandTotalDuty=" + txtGrandtotal.Text + ",ToalLandedCost=" + txttotallandedcost.Text;

                }
                if (intResult > 0)
                {
                    strsql = "Select Ident_Current('IVR_TRAN_ITEM') as TITID";
                    DataTable DTTranid = DU.getdata(strsql);
                    if (DTTranid.Rows.Count > 0)
                    {
                        //InsertItemTranDetails(strTranId, DTTranid.Rows[0]["TITID"].ToString(), i);
                    }
                    intResult = 0;
                }
            }
        }
    }
    protected void InsertImportItemTranTotal(string strTranId)
    {
        if (strTranId.ToString() != string.Empty)
        {
            int intResult = 0;
            SqlParameter[] sparam ={
                            new SqlParameter("@TRNID",strTranId.ToString()),
                            new SqlParameter("@TOTALITEMQTY",txttotalitemquantity.Text),
                            new SqlParameter("@ITEMTOTAL",Convert.ToDecimal(txtGross.Text)),
                            new SqlParameter("@TAXABLEAMOUNT",Convert.ToDecimal(txtTaxable.Text)),
                            new SqlParameter("@POSTTAXTOTAL","0"),
                            new SqlParameter("@FREIGHT",txtClearingfreight.Text),
                            new SqlParameter("@PACKAING",txtPackage.Text),
                            new SqlParameter("@INSURANCE",txtInsur.Text),
                            new SqlParameter("@ROUNDOFFAMT","0.00"),
                            //new SqlParameter("@RNDOFFAMT_LID",ddlRoundOff.SelectedValue),
                            new SqlParameter("@TRNTOTAL",Convert.ToDouble(txtImportGrandTotal.Text)),
                            new SqlParameter("@ASSESVALUE",txtAssesValue.Text),
                            new SqlParameter("@BCD",txtBasicCustomDuty.Text),
                            new SqlParameter("@CVD",txtCvd.Text),
                            new SqlParameter("@ECESSONCVD",txtEcessonCVD.Text),
                            new SqlParameter("@SHECESSONCVD",txtSHECessOnCVD.Text),
                            new SqlParameter("@CUSTOMEDUCESS",txtCustomeduCess.Text),
                            new SqlParameter("@SHCUSTOMEDUCESS",txtSHCustomEduCess.Text),
                            new SqlParameter("@ADDLDUTY",txtAddlDuty.Text),
                            new SqlParameter("@OTHERCHARGE",txtotherCharges.Text),
                            new SqlParameter("@DUTYPAYABLE",txtDutyPayable.Text)
                        };
            intResult = DU.executeprocedure("USP_IVR_TRAN_IMPORT_TOTAL", sparam);
            //ForLog
            PurchaseReceiveTotal = "TotalItemQty=" + txttotalitemquantity.Text + ",TotalGrossAmt=" + Convert.ToDecimal(txtGross.Text) + ",TaxableAmt=" + Convert.ToDecimal(txtTaxable.Text) + ",Freight=" + txtClearingfreight.Text + ",Packaging=" + txtPackage.Text + ",Insurance=" + txtInsur.Text + ",GrandTotal=" + Convert.ToDouble(txtImportGrandTotal.Text) +
                ",TotalAssesValue=" + txtAssesValue.Text + ",BCD=" + txtBasicCustomDuty.Text + ",CVD=" + txtCvd.Text + ",TotalEduCessCVD=" + txtEcessonCVD.Text +
                ",TotalHigherEduCessCVD=" + txtSHECessOnCVD.Text + ",CustomeEduCess=" + txtCustomeduCess.Text + ",HigherCustomeEduCess=" + txtSHCustomEduCess.Text +
                ",AdditionalDuty=" + txtAddlDuty.Text + ",OtherCharge=" + txtotherCharges.Text + ",DutyPayble=" + txtDutyPayable.Text + ",";
        }
    }
    protected void InsertImportTranOthers(string tranId)
    {
        if (tranId.ToString() != string.Empty)
        {
            SqlParameter[] sparam =
                                     {
                                         new SqlParameter("@TRNID",tranId.ToString()),
                                         new SqlParameter("@PREPAREDBY",txtPreparedBy.Text.Trim()),
                                         new SqlParameter("@CHECKEDBY",txtCheckedBy.Text.Trim()),
                                         new SqlParameter("@AUTHRSDSIGNAT",txtSignatory.Text.Trim()),
                                         new SqlParameter("@NARRATION",txtNarration.Text.Trim()),
                                         new SqlParameter("@REMARKS",txtRemark.Text.Trim())
                                     };
            DU.executeprocedure("USP_IVR_SaveTranOthers", sparam);
            //For Log
            PurchaseReceiveOthers = "PreparedBy=" + txtPreparedBy.Text + ",CheckedBy=" + txtCheckedBy.Text + ",AutherizedSignatory=" + txtSignatory.Text + ",Narration=" + txtNarration.Text + ",Remarks=" + txtRemark.Text + ",";
        }
    }
    protected void InsertImportTranDelivery(string tranId)
    {
        if (tranId.ToString() != string.Empty)
        {
            string strDeliveryDate = "1/1/1900";
            if (txtDeliveryDate.Text != string.Empty)
            {
                string[] str = txtDeliveryDate.Text.ToString().Split('/');
                strDeliveryDate = str[1] + "/" + str[0] + "/" + str[2];
            }
            SqlParameter[] sparam =
                                     {
                                         new SqlParameter("@TRNID",tranId.ToString()),
                                         new SqlParameter("@MODEOFDELIVERY",txtDeliveryMode.Text.Trim()),
                                         new SqlParameter("@DELIVERYDATE",strDeliveryDate) ,
                                         new SqlParameter("@DOCUMENTNUM",txtDocumentNo.Text.Trim()),
                                         new SqlParameter("@VEHICLENUM",txtVehicle.Text.Trim()),
                                         new SqlParameter("@TRANSPORTNAME",txtTransporter.Text.Trim()),
                                         new SqlParameter("@BILLINGADDRESS",txtBillAddress.Text),
                                         new SqlParameter("@DELIVERYADDRESS",txtDeliveryAdd.Text)
                                     };
            DU.executeprocedure("USP_IVR_SaveTranDelivery", sparam);
            //ForLog
            PurchaseReceiveDelivery = "ModeOfDelivery=" + txtDeliveryMode.Text + ",BillingAddress=" + txtBillAddress.Text + ",DeliveryAddress=" + txtDeliveryAdd.Text + ",DeliveryDate=" + strDeliveryDate + ",DocumentNo=" + txtDocumentNo.Text + ",VehicalNo=" + txtVehicle.Text + ",TransporterName=" + txtTransporter.Text;
        }
    }
}